1#if ADA_INCLUDE_URL_PATTERN
13 std::optional<std::string_view> protocol,
14 std::optional<std::string_view> username,
15 std::optional<std::string_view> password,
16 std::optional<std::string_view> hostname,
17 std::optional<std::string_view> port,
18 std::optional<std::string_view> pathname,
19 std::optional<std::string_view> search,
20 std::optional<std::string_view> hash) {
22 auto result = url_pattern_init{};
49 std::optional<url_aggregator>
base_url{};
52 if (init.base_url.has_value()) {
56 if (!parsing_result) {
59 base_url = std::move(*parsing_result);
63 if (!init.protocol.has_value()) {
65 std::string_view base_url_protocol =
base_url->get_protocol();
66 if (base_url_protocol.ends_with(
":")) base_url_protocol.remove_suffix(1);
75 !init.port && !init.username) {
86 !init.port && !init.username && !init.password) {
92 if (!init.protocol && !init.hostname) {
95 auto base_host =
base_url->get_hostname();
103 if (!init.protocol && !init.hostname && !init.port) {
112 if (!init.protocol && !init.hostname && !init.port && !init.pathname) {
119 if (!init.protocol && !init.hostname && !init.port && !init.pathname &&
130 if (!init.protocol && !init.hostname && !init.port && !init.pathname &&
131 !init.search && !init.hash) {
144 if (!process_result) {
145 return tl::unexpected(process_result.error());
147 result.protocol = std::move(*process_result);
152 if (init.username.has_value()) {
154 if (!process_result) {
155 return tl::unexpected(process_result.error());
157 result.username = std::move(*process_result);
162 if (init.password.has_value()) {
164 if (!process_result) {
165 return tl::unexpected(process_result.error());
167 result.password = std::move(*process_result);
172 if (init.hostname.has_value()) {
174 if (!process_result) {
175 return tl::unexpected(process_result.error());
177 result.hostname = std::move(*process_result);
183 auto process_result =
185 if (!process_result) {
186 return tl::unexpected(process_result.error());
188 result.port = std::move(*process_result);
192 if (init.pathname.has_value()) {
194 result.pathname = init.pathname;
213 auto slash_index = base_url_path.find_last_of(
'/');
216 if (slash_index != std::string::npos) {
219 base_url_path.resize(slash_index + 1);
222 base_url_path.append(std::move(*
result.pathname));
224 result.pathname = std::move(base_url_path);
230 auto pathname_processing_result =
232 if (!pathname_processing_result) {
233 return tl::unexpected(pathname_processing_result.error());
235 result.pathname = std::move(*pathname_processing_result);
242 if (!process_result) {
243 return tl::unexpected(process_result.error());
245 result.search = std::move(*process_result);
252 if (!process_result) {
253 return tl::unexpected(process_result.error());
255 result.hash = std::move(*process_result);
262 std::string_view value, process_type type) {
263 ada_log(
"process_protocol=", value,
" [", type,
"]");
266 if (value.ends_with(
":")) {
267 value.remove_suffix(1);
271 return std::string(value);
278 std::string_view value, process_type type) {
281 return std::string(value);
288 std::string_view value, process_type type) {
291 return std::string(value);
298 std::string_view value, process_type type) {
299 ada_log(
"process_hostname value=", value,
" type=", type);
302 return std::string(value);
309 std::string_view port, std::string_view protocol, process_type type) {
312 return std::string(
port);
320 std::string_view value, std::string_view protocol, process_type type) {
323 return std::string(value);
338 std::string_view value, process_type type) {
341 if (value.starts_with(
"?")) {
342 value.remove_prefix(1);
347 return std::string(value);
354 std::string_view value, process_type type) {
357 if (value.starts_with(
"#")) {
358 value.remove_prefix(1);
363 return std::string(value);
#define ADA_ASSERT_TRUE(COND)
tl::expected< std::string, errors > canonicalize_opaque_pathname(std::string_view input)
tl::expected< std::string, errors > canonicalize_pathname(std::string_view input)
tl::expected< std::string, errors > canonicalize_password(std::string_view input)
tl::expected< std::string, errors > canonicalize_protocol(std::string_view input)
tl::expected< std::string, errors > canonicalize_hostname(std::string_view input)
tl::expected< std::string, errors > canonicalize_port_with_protocol(std::string_view input, std::string_view protocol)
tl::expected< std::string, errors > canonicalize_hash(std::string_view input)
tl::expected< std::string, errors > canonicalize_search(std::string_view input)
constexpr bool is_absolute_pathname(std::string_view input, url_pattern_init::process_type type) noexcept
tl::expected< std::string, errors > canonicalize_username(std::string_view input)
std::string process_base_url_string(std::string_view input, url_pattern_init::process_type type)
template ada::result< url_aggregator > parse< url_aggregator >(std::string_view input, const url_aggregator *base_url)
tl::expected< result_type, ada::errors > result
std::optional< std::string > port
static tl::expected< std::string, errors > process_search(std::string_view value, process_type type)
std::optional< std::string > protocol
std::optional< std::string > password
std::optional< std::string > base_url
std::optional< std::string > hostname
std::optional< std::string > search
static tl::expected< std::string, errors > process_password(std::string_view value, process_type type)
std::optional< std::string > username
static tl::expected< url_pattern_init, errors > process(const url_pattern_init &init, process_type type, std::optional< std::string_view > protocol=std::nullopt, std::optional< std::string_view > username=std::nullopt, std::optional< std::string_view > password=std::nullopt, std::optional< std::string_view > hostname=std::nullopt, std::optional< std::string_view > port=std::nullopt, std::optional< std::string_view > pathname=std::nullopt, std::optional< std::string_view > search=std::nullopt, std::optional< std::string_view > hash=std::nullopt)
static tl::expected< std::string, errors > process_username(std::string_view value, process_type type)
static tl::expected< std::string, errors > process_pathname(std::string_view value, std::string_view protocol, process_type type)
static tl::expected< std::string, errors > process_hostname(std::string_view value, process_type type)
static tl::expected< std::string, errors > process_protocol(std::string_view value, process_type type)
std::optional< std::string > pathname
std::optional< std::string > hash
static tl::expected< std::string, errors > process_port(std::string_view port, std::string_view protocol, process_type type)
static tl::expected< std::string, errors > process_hash(std::string_view value, process_type type)
Declaration for the URLPattern inline functions.