@@ -19,11 +19,11 @@ namespace ada {
19
19
20
20
namespace parser {
21
21
template <typename result_type, typename url_pattern_init,
22
- typename url_pattern_options>
22
+ typename url_pattern_options, typename regex_provider >
23
23
tl::expected<result_type, errors> parse_url_pattern_impl (
24
24
std::variant<std::string_view, url_pattern_init> input,
25
25
const std::string_view* base_url, const url_pattern_options* options,
26
- url_pattern_regex::provider && regex_provider );
26
+ regex_provider && provider );
27
27
}
28
28
29
29
// Important: C++20 allows us to use concept rather than `using` or `typedef
@@ -207,37 +207,37 @@ struct url_pattern_component_result {
207
207
#endif // ADA_TESTING
208
208
};
209
209
210
+ template <class regex_provider , class regex_type >
211
+ requires url_pattern_regex::derived_from_provider<regex_provider, regex_type>
210
212
class url_pattern_component {
211
213
public:
212
214
url_pattern_component () = default ;
213
215
214
216
// This function explicitly takes a std::string because it is moved.
215
217
// To avoid unnecessary copy, move each value while calling the constructor.
216
- url_pattern_component (std::string&& new_pattern, std::regex&& new_regexp,
217
- std::regex_constants::syntax_option_type new_flags,
218
+ url_pattern_component (std::string&& new_pattern, regex_type&& new_regexp,
218
219
std::vector<std::string>&& new_group_name_list,
219
220
bool new_has_regexp_groups)
220
221
: regexp(std::move(new_regexp)),
221
222
pattern (std::move(new_pattern)),
222
- flags(new_flags),
223
223
group_name_list(new_group_name_list),
224
224
has_regexp_groups(new_has_regexp_groups) {}
225
225
226
226
// @see https://urlpattern.spec.whatwg.org/#compile-a-component
227
227
template <url_pattern_encoding_callback F>
228
228
static tl::expected<url_pattern_component, errors> compile (
229
229
std::string_view input, F& encoding_callback,
230
- url_pattern_compile_component_options& options);
230
+ url_pattern_compile_component_options& options,
231
+ const regex_provider& provider);
231
232
232
233
// @see https://urlpattern.spec.whatwg.org/#create-a-component-match-result
233
234
url_pattern_component_result create_component_match_result (
234
235
std::string_view input, const std::smatch& exec_result);
235
236
236
237
std::string to_string () const ;
237
238
238
- std::regex regexp{};
239
+ regex_type regexp{};
239
240
std::string pattern{};
240
- std::regex_constants::syntax_option_type flags = std::regex::ECMAScript;
241
241
std::vector<std::string> group_name_list{};
242
242
bool has_regexp_groups = false ;
243
243
};
@@ -270,10 +270,13 @@ struct url_pattern_options {
270
270
// defined in https://wicg.github.io/urlpattern.
271
271
// More information about the URL Pattern syntax can be found at
272
272
// https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
273
+ template <class regex_provider , class regex_type >
274
+ requires url_pattern_regex::derived_from_provider<regex_provider, regex_type>
273
275
class url_pattern {
274
276
public:
275
- explicit url_pattern (url_pattern_regex::provider&& regex_provider)
276
- : regex_provider_(std::move(regex_provider)) {}
277
+ explicit url_pattern (
278
+ url_pattern_regex::provider<regex_type>&& new_regex_provider)
279
+ : regex_provider_(std::move(new_regex_provider)) {}
277
280
278
281
/* *
279
282
* @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec
@@ -294,48 +297,48 @@ class url_pattern {
294
297
const url_pattern_input& input, std::string_view* base_url_string);
295
298
296
299
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol
297
- std::string_view get_protocol () const ada_lifetime_bound;
300
+ [[nodiscard]] std::string_view get_protocol () const ada_lifetime_bound;
298
301
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-username
299
- std::string_view get_username () const ada_lifetime_bound;
302
+ [[nodiscard]] std::string_view get_username () const ada_lifetime_bound;
300
303
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-password
301
- std::string_view get_password () const ada_lifetime_bound;
304
+ [[nodiscard]] std::string_view get_password () const ada_lifetime_bound;
302
305
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-hostname
303
- std::string_view get_hostname () const ada_lifetime_bound;
306
+ [[nodiscard]] std::string_view get_hostname () const ada_lifetime_bound;
304
307
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-port
305
- std::string_view get_port () const ada_lifetime_bound;
308
+ [[nodiscard]] std::string_view get_port () const ada_lifetime_bound;
306
309
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-pathname
307
- std::string_view get_pathname () const ada_lifetime_bound;
310
+ [[nodiscard]] std::string_view get_pathname () const ada_lifetime_bound;
308
311
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-search
309
- std::string_view get_search () const ada_lifetime_bound;
312
+ [[nodiscard]] std::string_view get_search () const ada_lifetime_bound;
310
313
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-hash
311
- std::string_view get_hash () const ada_lifetime_bound;
314
+ [[nodiscard]] std::string_view get_hash () const ada_lifetime_bound;
312
315
313
316
// If ignoreCase is true, the JavaScript regular expression created for each
314
317
// pattern must use the `vi` flag. Otherwise, they must use the `v` flag.
315
- bool ignore_case () const ;
318
+ [[nodiscard]] bool ignore_case () const ;
316
319
317
320
// @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
318
- bool has_regexp_groups () const ;
321
+ [[nodiscard]] bool has_regexp_groups () const ;
319
322
320
- std::string to_string () const ;
323
+ [[nodiscard]] std::string to_string () const ;
321
324
322
- url_pattern_component protocol_component{};
323
- url_pattern_component username_component{};
324
- url_pattern_component password_component{};
325
- url_pattern_component hostname_component{};
326
- url_pattern_component port_component{};
327
- url_pattern_component pathname_component{};
328
- url_pattern_component search_component{};
329
- url_pattern_component hash_component{};
325
+ url_pattern_component<regex_provider, regex_type> protocol_component{};
326
+ url_pattern_component<regex_provider, regex_type> username_component{};
327
+ url_pattern_component<regex_provider, regex_type> password_component{};
328
+ url_pattern_component<regex_provider, regex_type> hostname_component{};
329
+ url_pattern_component<regex_provider, regex_type> port_component{};
330
+ url_pattern_component<regex_provider, regex_type> pathname_component{};
331
+ url_pattern_component<regex_provider, regex_type> search_component{};
332
+ url_pattern_component<regex_provider, regex_type> hash_component{};
330
333
bool ignore_case_ = false ;
331
- url_pattern_regex::provider regex_provider_;
334
+ regex_provider regex_provider_;
332
335
333
336
template <typename result_type, typename url_pattern_init,
334
- typename url_pattern_options>
337
+ typename url_pattern_options, typename regex_provider_ >
335
338
friend tl::expected<result_type, errors> parser::parse_url_pattern_impl (
336
339
std::variant<std::string_view, url_pattern_init> input,
337
340
const std::string_view* base_url, const url_pattern_options* options,
338
- url_pattern_regex::provider && regex_provider );
341
+ regex_provider_ && provider );
339
342
};
340
343
341
344
} // namespace ada
0 commit comments