|
18 | 18 | #endif // ADA_TESTING
|
19 | 19 |
|
20 | 20 | namespace ada {
|
21 |
| - |
22 | 21 | namespace parser {
|
23 | 22 | template <typename result_type, typename url_pattern_init,
|
24 | 23 | typename url_pattern_options, typename regex_provider>
|
25 | 24 | tl::expected<result_type, errors> parse_url_pattern_impl(
|
26 | 25 | std::variant<std::string_view, url_pattern_init> input,
|
27 | 26 | const std::string_view* base_url, const url_pattern_options* options);
|
28 |
| -} |
29 |
| - |
30 |
| -// Important: C++20 allows us to use concept rather than `using` or `typedef |
31 |
| -// and allows functions with second argument, which is optional (using either |
32 |
| -// std::nullopt or a parameter with default value) |
33 |
| -template <typename F> |
34 |
| -concept url_pattern_encoding_callback = requires(F f, std::string_view sv) { |
35 |
| - { f(sv) } -> std::same_as<tl::expected<std::string, errors>>; |
36 |
| -}; |
37 |
| - |
38 |
| -// A structure providing matching patterns for individual components |
39 |
| -// of a URL. When a URLPattern is created, or when a URLPattern is |
40 |
| -// used to match or test against a URL, the input can be given as |
41 |
| -// either a string or a URLPatternInit struct. If a string is given, |
42 |
| -// it will be parsed to create a URLPatternInit. The URLPatternInit |
43 |
| -// API is defined as part of the URLPattern specification. |
44 |
| -struct url_pattern_init { |
45 |
| - // @see https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit |
46 |
| - static tl::expected<url_pattern_init, errors> process( |
47 |
| - url_pattern_init init, std::string_view type, |
48 |
| - std::optional<std::string_view> protocol = std::nullopt, |
49 |
| - std::optional<std::string_view> username = std::nullopt, |
50 |
| - std::optional<std::string_view> password = std::nullopt, |
51 |
| - std::optional<std::string_view> hostname = std::nullopt, |
52 |
| - std::optional<std::string_view> port = std::nullopt, |
53 |
| - std::optional<std::string_view> pathname = std::nullopt, |
54 |
| - std::optional<std::string_view> search = std::nullopt, |
55 |
| - std::optional<std::string_view> hash = std::nullopt); |
56 |
| - |
57 |
| - // @see https://urlpattern.spec.whatwg.org/#process-protocol-for-init |
58 |
| - static tl::expected<std::string, errors> process_protocol( |
59 |
| - std::string_view value, std::string_view type); |
60 |
| - |
61 |
| - // @see https://urlpattern.spec.whatwg.org/#process-username-for-init |
62 |
| - static tl::expected<std::string, errors> process_username( |
63 |
| - std::string_view value, std::string_view type); |
64 |
| - |
65 |
| - // @see https://urlpattern.spec.whatwg.org/#process-password-for-init |
66 |
| - static tl::expected<std::string, errors> process_password( |
67 |
| - std::string_view value, std::string_view type); |
68 |
| - |
69 |
| - // @see https://urlpattern.spec.whatwg.org/#process-hostname-for-init |
70 |
| - static tl::expected<std::string, errors> process_hostname( |
71 |
| - std::string_view value, std::string_view type); |
72 |
| - |
73 |
| - // @see https://urlpattern.spec.whatwg.org/#process-port-for-init |
74 |
| - static tl::expected<std::string, errors> process_port( |
75 |
| - std::string_view port, std::string_view protocol, std::string_view type); |
76 |
| - |
77 |
| - // @see https://urlpattern.spec.whatwg.org/#process-pathname-for-init |
78 |
| - static tl::expected<std::string, errors> process_pathname( |
79 |
| - std::string_view value, std::string_view protocol, std::string_view type); |
80 |
| - |
81 |
| - // @see https://urlpattern.spec.whatwg.org/#process-search-for-init |
82 |
| - static tl::expected<std::string, errors> process_search( |
83 |
| - std::string_view value, std::string_view type); |
84 |
| - |
85 |
| - // @see https://urlpattern.spec.whatwg.org/#process-hash-for-init |
86 |
| - static tl::expected<std::string, errors> process_hash(std::string_view value, |
87 |
| - std::string_view type); |
88 |
| - |
89 |
| - [[nodiscard]] std::string to_string() const; |
90 |
| - |
91 |
| - bool operator==(const url_pattern_init&) const; |
92 |
| - |
93 |
| - std::optional<std::string> protocol{}; |
94 |
| - std::optional<std::string> username{}; |
95 |
| - std::optional<std::string> password{}; |
96 |
| - std::optional<std::string> hostname{}; |
97 |
| - std::optional<std::string> port{}; |
98 |
| - std::optional<std::string> pathname{}; |
99 |
| - std::optional<std::string> search{}; |
100 |
| - std::optional<std::string> hash{}; |
101 |
| - std::optional<std::string> base_url{}; |
102 |
| -}; |
| 27 | +} // namespace parser |
103 | 28 |
|
104 | 29 | enum class url_pattern_part_type : uint8_t {
|
105 | 30 | // The part represents a simple fixed text string.
|
@@ -330,12 +255,14 @@ class url_pattern {
|
330 | 255 | bool ignore_case_ = false;
|
331 | 256 |
|
332 | 257 | template <typename result_type, typename url_pattern_init,
|
333 |
| - typename url_pattern_options> |
| 258 | + typename url_pattern_options, typename regex_provider> |
334 | 259 | friend tl::expected<result_type, errors> parser::parse_url_pattern_impl(
|
335 | 260 | std::variant<std::string_view, url_pattern_init> input,
|
336 | 261 | const std::string_view* base_url, const url_pattern_options* options);
|
337 | 262 | };
|
338 | 263 |
|
| 264 | + |
| 265 | + |
339 | 266 | } // namespace ada
|
340 | 267 |
|
341 | 268 | #endif
|
0 commit comments