99#include " ada/expected.h"
1010#include " ada/url_pattern_regex.h"
1111
12+ #include < _regex.h>
1213#include < regex>
1314#include < string>
1415#include < unordered_map>
@@ -19,11 +20,11 @@ namespace ada {
1920
2021namespace parser {
2122template <typename result_type, typename url_pattern_init,
22- typename url_pattern_options>
23+ typename url_pattern_options, class regex_type >
2324tl::expected<result_type, errors> parse_url_pattern_impl (
2425 std::variant<std::string_view, url_pattern_init> input,
2526 const std::string_view* base_url, const url_pattern_options* options,
26- url_pattern_regex::provider&& regex_provider);
27+ url_pattern_regex::provider<regex_type> && regex_provider);
2728}
2829
2930// Important: C++20 allows us to use concept rather than `using` or `typedef
@@ -207,37 +208,36 @@ struct url_pattern_component_result {
207208#endif // ADA_TESTING
208209};
209210
211+ template <class 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 url_pattern_regex::provider<regex_type>& regex_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,9 +270,10 @@ 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_type = std::regex>
273274class url_pattern {
274275 public:
275- explicit url_pattern (url_pattern_regex::provider&& regex_provider)
276+ explicit url_pattern (url_pattern_regex::provider<regex_type> && regex_provider)
276277 : regex_provider_(std::move(regex_provider)) {}
277278
278279 /* *
@@ -319,23 +320,23 @@ class url_pattern {
319320
320321 std::string to_string () const ;
321322
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{};
323+ url_pattern_component<regex_type> protocol_component{};
324+ url_pattern_component<regex_type> username_component{};
325+ url_pattern_component<regex_type> password_component{};
326+ url_pattern_component<regex_type> hostname_component{};
327+ url_pattern_component<regex_type> port_component{};
328+ url_pattern_component<regex_type> pathname_component{};
329+ url_pattern_component<regex_type> search_component{};
330+ url_pattern_component<regex_type> hash_component{};
330331 bool ignore_case_ = false ;
331- url_pattern_regex::provider regex_provider_;
332+ url_pattern_regex::provider<regex_type> regex_provider_;
332333
333334 template <typename result_type, typename url_pattern_init,
334- typename url_pattern_options>
335+ typename url_pattern_options, typename regex_provider_type >
335336 friend tl::expected<result_type, errors> parser::parse_url_pattern_impl (
336337 std::variant<std::string_view, url_pattern_init> input,
337338 const std::string_view* base_url, const url_pattern_options* options,
338- url_pattern_regex::provider&& regex_provider);
339+ url_pattern_regex::provider<regex_provider_type> && regex_provider);
339340};
340341
341342} // namespace ada
0 commit comments