5#ifndef ADA_URL_PATTERN_INL_H
6#define ADA_URL_PATTERN_INL_H
28template <url_pattern_regex::regex_concept regex_prov
ider>
31 std::string_view input,
32 std::vector<std::optional<std::string>>&& exec_result) {
40 result.groups.reserve(exec_result.size());
45 for (
size_t index = 0; index < exec_result.size(); index++) {
48 std::move(exec_result[index]),
54template <url_pattern_regex::regex_concept regex_prov
ider>
58 return protocol_component.pattern;
60template <url_pattern_regex::regex_concept regex_prov
ider>
64 return username_component.pattern;
66template <url_pattern_regex::regex_concept regex_prov
ider>
70 return password_component.pattern;
72template <url_pattern_regex::regex_concept regex_prov
ider>
76 return hostname_component.pattern;
78template <url_pattern_regex::regex_concept regex_prov
ider>
82 return port_component.pattern;
84template <url_pattern_regex::regex_concept regex_prov
ider>
88 return pathname_component.pattern;
90template <url_pattern_regex::regex_concept regex_prov
ider>
94 return search_component.pattern;
96template <url_pattern_regex::regex_concept regex_prov
ider>
100 return hash_component.pattern;
102template <url_pattern_regex::regex_concept regex_prov
ider>
106template <url_pattern_regex::regex_concept regex_prov
ider>
109 return protocol_component.has_regexp_groups ||
110 username_component.has_regexp_groups ||
111 password_component.has_regexp_groups ||
112 hostname_component.has_regexp_groups ||
113 port_component.has_regexp_groups ||
114 pathname_component.has_regexp_groups ||
115 search_component.has_regexp_groups || hash_component.has_regexp_groups;
125 return {&delimiter.value(), 1};
133 return {&prefix.value(), 1};
138template <url_pattern_regex::regex_concept regex_prov
ider>
139template <url_pattern_encoding_callback F>
140tl::expected<url_pattern_component<regex_provider>,
errors>
142 std::string_view input, F& encoding_callback,
144 ada_log(
"url_pattern_component::compile input: ", input);
151 ada_log(
"parse_pattern_string failed");
152 return tl::unexpected(part_list.error());
157 auto [regular_expression_string, name_list] =
161 ada_log(
"regular expression string: ", regular_expression_string);
165 auto pattern_string =
171 std::optional<typename regex_provider::regex_type> regular_expression =
172 regex_provider::create_instance(regular_expression_string,
175 if (!regular_expression) {
181 const auto has_regexp = [](
const auto& part) {
return part.is_regexp(); };
190 std::move(pattern_string), std::move(*regular_expression),
194template <url_pattern_regex::regex_concept regex_prov
ider>
199 return match(input, base_url);
202template <url_pattern_regex::regex_concept regex_prov
ider>
211 return result->has_value();
216template <url_pattern_regex::regex_concept regex_prov
ider>
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");
247 std::get<url_pattern_init>(input),
"url", protocol, username, password,
248 hostname, port, pathname, search, hash);
251 if (!apply_result.has_value()) {
252 ada_log(
"match returned std::nullopt because process threw");
258 protocol = apply_result->protocol.value();
262 username = apply_result->username.value();
266 password = apply_result->password.value();
270 hostname = apply_result->hostname.value();
274 port = apply_result->port.value();
278 pathname = apply_result->pathname.value();
282 if (apply_result->search->starts_with(
"?")) {
283 search = apply_result->search->substr(1);
285 search = apply_result->search.value();
291 hash = 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.value() :
nullptr;
323 ada_log(
"match returned std::nullopt because url failed");
368 auto protocol_exec_result =
369 regex_provider::regex_search(protocol, protocol_component.regexp);
373 auto username_exec_result =
374 regex_provider::regex_search(username, username_component.regexp);
378 auto password_exec_result =
379 regex_provider::regex_search(password, password_component.regexp);
383 auto hostname_exec_result =
384 regex_provider::regex_search(hostname, hostname_component.regexp);
388 auto port_exec_result =
389 regex_provider::regex_search(port, port_component.regexp);
393 auto pathname_exec_result =
394 regex_provider::regex_search(pathname, pathname_component.regexp);
398 auto search_exec_result =
399 regex_provider::regex_search(search, search_component.regexp);
403 auto hash_exec_result =
404 regex_provider::regex_search(hash, hash_component.regexp);
409 if (!protocol_exec_result || !username_exec_result || !password_exec_result ||
410 !hostname_exec_result || !port_exec_result || !pathname_exec_result ||
411 !search_exec_result || !hash_exec_result) {
418 result.inputs = std::move(inputs);
421 result.protocol = protocol_component.create_component_match_result(
422 protocol, std::move(*protocol_exec_result));
426 result.username = username_component.create_component_match_result(
427 username, std::move(*username_exec_result));
431 result.password = password_component.create_component_match_result(
432 password, std::move(*password_exec_result));
436 result.hostname = hostname_component.create_component_match_result(
437 hostname, std::move(*hostname_exec_result));
441 result.port = port_component.create_component_match_result(
442 port, std::move(*port_exec_result));
446 result.pathname = pathname_component.create_component_match_result(
447 pathname, std::move(*pathname_exec_result));
451 result.search = search_component.create_component_match_result(
452 search, std::move(*search_exec_result));
456 result.hash = hash_component.create_component_match_result(
457 hash, std::move(*hash_exec_result));
url_pattern_component()=default
static tl::expected< url_pattern_component, errors > compile(std::string_view input, F &encoding_callback, url_pattern_compile_component_options &options)
std::vector< std::string > group_name_list
url_pattern_component_result create_component_match_result(std::string_view input, std::vector< std::optional< std::string > > &&exec_result)
bool is_regexp() const noexcept
url_pattern_part_type type
bool has_regexp_groups() const
std::string_view get_hostname() const ada_lifetime_bound
std::string_view get_port() const ada_lifetime_bound
result< bool > test(const url_pattern_input &input, const std::string_view *base_url=nullptr)
result< std::optional< url_pattern_result > > match(const url_pattern_input &input, const std::string_view *base_url_string=nullptr)
std::string_view get_password() const ada_lifetime_bound
std::string_view get_protocol() const ada_lifetime_bound
std::string_view get_hash() const ada_lifetime_bound
std::string_view get_username() const ada_lifetime_bound
std::string_view get_pathname() const ada_lifetime_bound
std::string_view get_search() const ada_lifetime_bound
result< std::optional< url_pattern_result > > exec(const url_pattern_input &input, const std::string_view *base_url=nullptr)
Common definitions for cross-platform compiler support.
#define ADA_ASSERT_TRUE(COND)
#define ada_lifetime_bound
tl::expected< std::vector< url_pattern_part >, errors > parse_pattern_string(std::string_view input, url_pattern_compile_component_options &options, F &encoding_callback)
std::string generate_pattern_string(std::vector< url_pattern_part > &part_list, url_pattern_compile_component_options &options)
std::tuple< std::string, std::vector< std::string > > generate_regular_expression_and_name_list(const std::vector< url_pattern_part > &part_list, url_pattern_compile_component_options options)
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::variant< std::string_view, url_pattern_init > url_pattern_input
std::string_view get_prefix() const ada_warn_unused
std::string_view get_delimiter() const ada_warn_unused
bool operator==(const url_pattern_component_result &) const
std::unordered_map< std::string, std::optional< std::string > > groups
std::optional< std::string > port
std::optional< std::string > protocol
static tl::expected< url_pattern_init, errors > process(url_pattern_init init, std::string_view 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)
std::optional< std::string > password
std::optional< std::string > hostname
std::optional< std::string > search
bool operator==(const url_pattern_init &) const
std::optional< std::string > username
std::optional< std::string > pathname
std::optional< std::string > hash
Generic URL struct reliant on std::string instantiation.
std::string get_search() const noexcept
constexpr std::string_view get_pathname() const noexcept
std::string get_hash() const noexcept
std::string get_hostname() const noexcept
const std::string & get_password() const noexcept
std::string get_port() const noexcept
const std::string & get_username() const noexcept
constexpr bool has_search() const noexcept override
std::string get_protocol() const noexcept
constexpr bool has_hash() const noexcept override
Declaration for the URLPattern implementation.
Declaration for the URLPattern helpers.