5#ifndef ADA_URL_PATTERN_H
6#define ADA_URL_PATTERN_H
9#include "ada/expected.h"
14#include <unordered_map>
60 std::string&& _prefix, std::string&& _suffix)
88 std::optional<char> new_delimiter = std::nullopt,
89 std::optional<char> new_prefix = std::nullopt)
90 : delimiter(new_delimiter), prefix(new_prefix) {}
106 std::optional<char>
prefix{};
111inline url_pattern_compile_component_options
116inline url_pattern_compile_component_options
121inline url_pattern_compile_component_options
131 std::unordered_map<std::string, std::optional<std::string>>
groups;
138 *os <<
"input: '" <<
result.input <<
"', group: ";
139 for (
const auto& group :
result.groups) {
140 *os <<
"(" << group.first <<
", " << group.second.value_or(
"undefined")
147template <url_pattern_regex::regex_concept regex_prov
ider>
155 typename regex_provider::regex_type&& new_regexp,
156 std::vector<std::string>&& new_group_name_list,
157 bool new_has_regexp_groups)
158 :
regexp(std::move(new_regexp)),
159 pattern(std::move(new_pattern)),
164 template <url_pattern_encoding_callback F>
165 static tl::expected<url_pattern_component, errors>
compile(
166 std::string_view input, F& encoding_callback,
171 std::string_view input,
172 std::vector<std::optional<std::string>>&& exec_result);
177 *os <<
"pattern: '" << component.
pattern
179 <<
"group_name_list: ";
186 typename regex_provider::regex_type
regexp{};
224template <url_pattern_regex::regex_concept regex_prov
ider>
234 const std::string_view* base_url =
nullptr);
240 const std::string_view* base_url =
nullptr);
248 const std::string_view* base_url_string =
nullptr);
275 friend void PrintTo(
const url_pattern& c, std::ostream* os) {
276 *os <<
"protocol_component: '" << c.
get_protocol() <<
", ";
277 *os <<
"username_component: '" << c.
get_username() <<
", ";
278 *os <<
"password_component: '" << c.
get_password() <<
", ";
279 *os <<
"hostname_component: '" << c.
get_hostname() <<
", ";
280 *os <<
"port_component: '" << c.
get_port() <<
", ";
281 *os <<
"pathname_component: '" << c.
get_pathname() <<
", ";
282 *os <<
"search_component: '" << c.
get_search() <<
", ";
283 *os <<
"hash_component: '" << c.
get_hash();
287 template <url_pattern_regex::regex_concept P>
289 std::variant<std::string_view, url_pattern_init> input,
309 url_pattern_component<regex_provider> password_component{};
315 url_pattern_component<regex_provider> hostname_component{};
321 url_pattern_component<regex_provider> port_component{};
327 url_pattern_component<regex_provider> pathname_component{};
333 url_pattern_component<regex_provider> search_component{};
339 url_pattern_component<regex_provider> hash_component{};
345 bool ignore_case_ =
false;
url_pattern_component(std::string &&new_pattern, typename regex_provider::regex_type &&new_regexp, std::vector< std::string > &&new_group_name_list, bool new_has_regexp_groups)
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)
regex_provider::regex_type regexp
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)
url_pattern_part(url_pattern_part_type _type, std::string &&_value, url_pattern_part_modifier _modifier)
url_pattern_part(url_pattern_part_type _type, std::string &&_value, url_pattern_part_modifier _modifier, std::string &&_name, std::string &&_prefix, std::string &&_suffix)
url_pattern_part_modifier modifier
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)
#define ada_lifetime_bound
Definitions for user facing functions for parsing URL and it's components.
tl::expected< url_pattern< regex_provider >, errors > parse_url_pattern_impl(std::variant< std::string_view, url_pattern_init > input, const std::string_view *base_url, const url_pattern_options *options)
url_pattern_part_modifier
tl::expected< result_type, ada::errors > result
std::variant< std::string_view, url_pattern_init > url_pattern_input
Definitions for the parser.
url_pattern_compile_component_options(std::optional< char > new_delimiter=std::nullopt, std::optional< char > new_prefix=std::nullopt)
static url_pattern_compile_component_options HOSTNAME
url_pattern_compile_component_options()=default
static url_pattern_compile_component_options PATHNAME
static url_pattern_compile_component_options DEFAULT
bool operator==(const url_pattern_component_result &) const
std::unordered_map< std::string, std::optional< std::string > > groups
std::vector< url_pattern_input > inputs
url_pattern_component_result hostname
url_pattern_component_result password
url_pattern_component_result hash
url_pattern_component_result port
url_pattern_component_result protocol
url_pattern_component_result pathname
url_pattern_component_result username
url_pattern_component_result search
Declaration for the url_pattern_init implementation.