@@ -19,11 +19,11 @@ namespace ada {
1919
2020namespace parser {
2121template <typename result_type, typename url_pattern_init,
22- typename url_pattern_options>
22+ typename url_pattern_options, typename regex_provider >
2323tl::expected<result_type, errors> parse_url_pattern_impl (
2424 std::variant<std::string_view, url_pattern_init> input,
2525 const std::string_view* base_url, const url_pattern_options* options,
26- url_pattern_regex::provider && regex_provider );
26+ regex_provider && provider );
2727}
2828
2929// Important: C++20 allows us to use concept rather than `using` or `typedef
@@ -207,37 +207,37 @@ struct url_pattern_component_result {
207207#endif // ADA_TESTING
208208};
209209
210+ template <class regex_provider , class regex_type >
211+ requires url_pattern_regex::derived_from_provider<regex_provider, regex_type>
210212class url_pattern_component {
211213 public:
212214 url_pattern_component () = default ;
213215
214216 // This function explicitly takes a std::string because it is moved.
215217 // 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,
218219 std::vector<std::string>&& new_group_name_list,
219220 bool new_has_regexp_groups)
220221 : regexp(std::move(new_regexp)),
221222 pattern (std::move(new_pattern)),
222- flags(new_flags),
223223 group_name_list(new_group_name_list),
224224 has_regexp_groups(new_has_regexp_groups) {}
225225
226226 // @see https://urlpattern.spec.whatwg.org/#compile-a-component
227227 template <url_pattern_encoding_callback F>
228228 static tl::expected<url_pattern_component, errors> compile (
229229 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);
231232
232233 // @see https://urlpattern.spec.whatwg.org/#create-a-component-match-result
233234 url_pattern_component_result create_component_match_result (
234235 std::string_view input, const std::smatch& exec_result);
235236
236237 std::string to_string () const ;
237238
238- std::regex regexp{};
239+ regex_type regexp{};
239240 std::string pattern{};
240- std::regex_constants::syntax_option_type flags = std::regex::ECMAScript;
241241 std::vector<std::string> group_name_list{};
242242 bool has_regexp_groups = false ;
243243};
@@ -270,10 +270,13 @@ struct url_pattern_options {
270270// defined in https://wicg.github.io/urlpattern.
271271// More information about the URL Pattern syntax can be found at
272272// 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>
273275class url_pattern {
274276 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)) {}
277280
278281 /* *
279282 * @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec
@@ -294,48 +297,48 @@ class url_pattern {
294297 const url_pattern_input& input, std::string_view* base_url_string);
295298
296299 // @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;
298301 // @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;
300303 // @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;
302305 // @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;
304307 // @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;
306309 // @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;
308311 // @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;
310313 // @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;
312315
313316 // If ignoreCase is true, the JavaScript regular expression created for each
314317 // pattern must use the `vi` flag. Otherwise, they must use the `v` flag.
315- bool ignore_case () const ;
318+ [[nodiscard]] bool ignore_case () const ;
316319
317320 // @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
318- bool has_regexp_groups () const ;
321+ [[nodiscard]] bool has_regexp_groups () const ;
319322
320- std::string to_string () const ;
323+ [[nodiscard]] std::string to_string () const ;
321324
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{};
330333 bool ignore_case_ = false ;
331- url_pattern_regex::provider regex_provider_;
334+ regex_provider regex_provider_;
332335
333336 template <typename result_type, typename url_pattern_init,
334- typename url_pattern_options>
337+ typename url_pattern_options, typename regex_provider_ >
335338 friend tl::expected<result_type, errors> parser::parse_url_pattern_impl (
336339 std::variant<std::string_view, url_pattern_init> input,
337340 const std::string_view* base_url, const url_pattern_options* options,
338- url_pattern_regex::provider && regex_provider );
341+ regex_provider_ && provider );
339342};
340343
341344} // namespace ada
0 commit comments