Upa URL C++ library
A WHATWG URL Standard implementation
Loading...
Searching...
No Matches
url_result.h
Go to the documentation of this file.
1// Copyright 2016-2026 Rimas Misevičius
2// Distributed under the BSD-style license that can be
3// found in the LICENSE file.
4//
5
6#ifndef UPA_URL_RESULT_H
7#define UPA_URL_RESULT_H
8
9#include "config.h"
10
11#ifndef UPA_MODULE
12# include <stdexcept>
13#endif // UPA_MODULE
14
15namespace upa {
16
17UPA_EXPORT_BEGIN
18
22enum class validation_errc {
23 // Success:
24 ok = 0,
25 // Ignored input (for internal use):
29
30 // Standard validation error codes
31 // https://url.spec.whatwg.org/#validation-error
32
33 // Non-failure (only ipv4_out_of_range_part indicates failure in some cases,
34 // see: https://url.spec.whatwg.org/#ipv4-out-of-range-part):
35 // IDNA
37 // Host parsing
41 // URL parsing
49
50 // Failure:
51 // IDNA
53 // Host parsing
72 // URL parsing
79
80 // Non-standard error codes (indicates failure)
81
84 // url_from_file_path errors
87 // path_from_file_url errors
94};
95
98[[nodiscard]] constexpr bool success(validation_errc res) noexcept {
99 return res == validation_errc::ok;
100}
101
103class UPA_SO_VISIBLE url_error : public std::runtime_error {
104public:
109 inline explicit url_error(validation_errc res, const char* what_arg)
110 : std::runtime_error(what_arg)
111 , res_(res)
112 {}
113
115 [[nodiscard]] inline validation_errc result() const noexcept {
116 return res_;
117 }
118private:
119 validation_errc res_;
120};
121
122UPA_EXPORT_END
123
124namespace detail {
125
127
128template<typename T, typename R = bool>
129struct result_value {
130 T value{};
131 R result{};
132
133 constexpr result_value(R res) noexcept
134 : result(res) {}
135 constexpr result_value(R res, T val) noexcept
136 : value(val), result(res) {}
137 [[nodiscard]] constexpr operator R() const noexcept {
138 return result;
139 }
140};
141
142} // namespace detail
143} // namespace upa
144
145#endif // UPA_URL_RESULT_H
validation_errc result() const noexcept
Definition url_result.h:115
url_error(validation_errc res, const char *what_arg)
Definition url_result.h:109
Definition url.h:3418
Definition url.h:50
constexpr bool success(validation_errc res) noexcept
Check validation error code indicates success.
Definition url_result.h:98
validation_errc
URL validation and other error codes.
Definition url_result.h:22
@ invalid_base
Invalid base.
Definition url_result.h:83
@ ipv6_invalid_compression
An IPv6 address begins with improper compression.
Definition url_result.h:59
@ overflow
URL is too long.
Definition url_result.h:82
@ ipv4_in_ipv6_too_many_pieces
An IPv6 address with IPv4 address syntax: the IPv6 address has more than 6 pieces.
Definition url_result.h:65
@ host_invalid_code_point
An opaque host contains a forbidden host code point.
Definition url_result.h:55
@ ipv6_multiple_compression
An IPv6 address is compressed in more than one spot.
Definition url_result.h:61
@ file_url_not_windows_path
Not a Windows path in file URL.
Definition url_result.h:92
@ ipv4_non_numeric_part
An IPv4 address part is not numeric.
Definition url_result.h:57
@ special_scheme_missing_following_solidus
The input’s scheme is not followed by "//".
Definition url_result.h:43
@ port_out_of_range
The input’s port is too big.
Definition url_result.h:77
@ invalid_credentials
The input includes credentials.
Definition url_result.h:45
@ file_url_cannot_have_host
POSIX path cannot have host.
Definition url_result.h:89
@ ipv4_empty_part
An IPv4 address ends with a U+002E (.).
Definition url_result.h:38
@ not_file_url
Not a file URL.
Definition url_result.h:88
@ null_character
Path contains null character.
Definition url_result.h:93
@ file_invalid_windows_drive_letter_host
A file: URL’s host is a Windows drive letter.
Definition url_result.h:48
@ ipv6_too_many_pieces
An IPv6 address contains more than 8 pieces.
Definition url_result.h:60
@ file_url_unsupported_host
UNC path cannot have "." hostname.
Definition url_result.h:90
@ ipv4_in_ipv6_too_few_parts
An IPv6 address with IPv4 address syntax: an IPv4 address contains too few parts.
Definition url_result.h:71
@ file_url_invalid_unc
Invalid UNC path in file URL.
Definition url_result.h:91
@ domain_invalid_code_point
Unused, use domain_to_ascii instead.
Definition url_result.h:54
@ ipv6_too_few_pieces
An uncompressed IPv6 address contains fewer than 8 pieces.
Definition url_result.h:64
@ host_missing
The input has a special scheme, but does not contain a host.
Definition url_result.h:76
@ file_unsupported_path
Unsupported file path (e.g. non-absolute).
Definition url_result.h:86
@ ipv4_too_many_parts
An IPv4 address does not consist of exactly 4 parts.
Definition url_result.h:56
@ invalid_reverse_solidus
The URL has a special scheme and it uses U+005C () instead of U+002F (/).
Definition url_result.h:44
@ domain_to_ascii
Unicode ToASCII records an error or returns the empty string.
Definition url_result.h:52
@ ipv4_non_decimal_part
The IPv4 address contains numbers expressed using hexadecimal or octal digits.
Definition url_result.h:39
@ file_empty_path
Path cannot be empty.
Definition url_result.h:85
@ ipv4_in_ipv6_out_of_range_part
An IPv6 address with IPv4 address syntax: an IPv4 part exceeds 255.
Definition url_result.h:70
@ ipv6_unclosed
An IPv6 address is missing the closing U+005D (]).
Definition url_result.h:58
@ port_invalid
The input’s port is invalid.
Definition url_result.h:78
@ ipv4_out_of_range_part
An IPv4 address part exceeds 255.
Definition url_result.h:40
@ invalid_url_unit
A code point is found that is not a URL unit.
Definition url_result.h:42
@ ignored
Setter ignored the value (internal).
Definition url_result.h:26
bool domain_to_unicode(std::basic_string< CharT > &output, const StrT &input, bool be_strict=false, bool is_input_ascii=false)
Implements the domain to Unicode algorithm.
Definition url_host.h:228