219 std::string protocol{};
220 std::string username{};
221 std::string password{};
222 std::string hostname{};
224 std::string pathname{};
225 std::string search{};
230 std::vector inputs{input};
233 if (std::holds_alternative<url_pattern_init>(input)) {
235 "url_pattern::match called with url_pattern_init and base_url_string=",
238 if (base_url_string) {
239 ada_log(
"failed to match because base_url_string was given");
248 protocol, username, password, hostname, port, pathname, search, hash);
251 if (!apply_result.has_value()) {
252 ada_log(
"match returned std::nullopt because process threw");
258 protocol = std::move(apply_result->protocol.value());
262 username = std::move(apply_result->username.value());
266 password = std::move(apply_result->password.value());
270 hostname = std::move(apply_result->hostname.value());
274 port = std::move(apply_result->port.value());
278 pathname = std::move(apply_result->pathname.value());
282 if (apply_result->search->starts_with(
"?")) {
283 search = apply_result->search->substr(1);
285 search = std::move(apply_result->search.value());
291 hash = std::move(apply_result->hash.value());
299 if (base_url_string) {
305 ada_log(
"match returned std::nullopt because failed to parse base_url=",
311 inputs.emplace_back(*base_url_string);
315 base_url.has_value() ? &*base_url :
nullptr;
323 ada_log(
"match returned std::nullopt because url failed");
350 search = view.starts_with(
"?") ?
url->
get_search().substr(1) : view;
360 hash = view.starts_with(
"#") ?
url->
get_hash().substr(1) : view;
368 auto protocol_exec_result =
369 regex_provider::regex_search(protocol, protocol_component.regexp);
371 if (!protocol_exec_result) {
377 auto username_exec_result =
378 regex_provider::regex_search(username, username_component.regexp);
380 if (!username_exec_result) {
386 auto password_exec_result =
387 regex_provider::regex_search(password, password_component.regexp);
389 if (!password_exec_result) {
395 auto hostname_exec_result =
396 regex_provider::regex_search(hostname, hostname_component.regexp);
398 if (!hostname_exec_result) {
404 auto port_exec_result =
405 regex_provider::regex_search(port, port_component.regexp);
407 if (!port_exec_result) {
413 auto pathname_exec_result =
414 regex_provider::regex_search(pathname, pathname_component.regexp);
416 if (!pathname_exec_result) {
422 auto search_exec_result =
423 regex_provider::regex_search(search, search_component.regexp);
425 if (!search_exec_result) {
431 auto hash_exec_result =
432 regex_provider::regex_search(hash, hash_component.regexp);
434 if (!hash_exec_result) {
441 result.inputs = std::move(inputs);
444 result.protocol = protocol_component.create_component_match_result(
445 std::move(protocol), std::move(*protocol_exec_result));
449 result.username = username_component.create_component_match_result(
450 std::move(username), std::move(*username_exec_result));
454 result.password = password_component.create_component_match_result(
455 std::move(password), std::move(*password_exec_result));
459 result.hostname = hostname_component.create_component_match_result(
460 std::move(hostname), std::move(*hostname_exec_result));
464 result.port = port_component.create_component_match_result(
465 std::move(port), std::move(*port_exec_result));
469 result.pathname = pathname_component.create_component_match_result(
470 std::move(pathname), std::move(*pathname_exec_result));
474 result.search = search_component.create_component_match_result(
475 std::move(search), std::move(*search_exec_result));
479 result.hash = hash_component.create_component_match_result(
480 std::move(hash), std::move(*hash_exec_result));
static tl::expected< url_pattern_init, errors > process(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)