| 9069 | template <url_pattern_regex::regex_concept regex_provider> |
| 9070 | template <url_pattern_encoding_callback F> |
| 9071 | tl::expected<url_pattern_component<regex_provider>, errors> |
| 9072 | url_pattern_component<regex_provider>::compile( |
| 9073 | std::string_view input, F& encoding_callback, |
| 9074 | url_pattern_compile_component_options& options) { |
| 9075 | ada_log("url_pattern_component::compile input: ", input); |
| 9076 | // Let part list be the result of running parse a pattern string given input, |
| 9077 | // options, and encoding callback. |
| 9078 | auto part_list = url_pattern_helpers::parse_pattern_string(input, options, |
| 9079 | encoding_callback); |
| 9080 | |
| 9081 | if (!part_list) { |
| 9082 | ada_log("parse_pattern_string failed"); |
| 9083 | return tl::unexpected(part_list.error()); |
| 9084 | } |
| 9085 | |
| 9086 | // Let (regular expression string, name list) be the result of running |
| 9087 | // generate a regular expression and name list given part list and options. |
| 9088 | auto [regular_expression_string, name_list] = |
| 9089 | url_pattern_helpers::generate_regular_expression_and_name_list(*part_list, |
| 9090 | options); |
| 9091 | |
| 9092 | ada_log("regular expression string: ", regular_expression_string); |
| 9093 | |
| 9094 | // Let pattern string be the result of running generate a pattern |
| 9095 | // string given part list and options. |
| 9096 | auto pattern_string = |
| 9097 | url_pattern_helpers::generate_pattern_string(*part_list, options); |
| 9098 | |
| 9099 | // Let regular expression be RegExpCreate(regular expression string, |
| 9100 | // flags). If this throws an exception, catch it, and throw a |
| 9101 | // TypeError. |
| 9102 | std::optional<typename regex_provider::regex_type> regular_expression = |
| 9103 | regex_provider::create_instance(regular_expression_string, |
| 9104 | options.ignore_case); |
| 9105 | |
| 9106 | if (!regular_expression) { |
| 9107 | return tl::unexpected(errors::type_error); |
| 9108 | } |
| 9109 | |
| 9110 | // For each part of part list: |
| 9111 | // - If part's type is "regexp", then set has regexp groups to true. |
| 9112 | const auto has_regexp = [](const auto& part) { return part.is_regexp(); }; |
| 9113 | const bool has_regexp_groups = std::ranges::any_of(*part_list, has_regexp); |
| 9114 | |
| 9115 | ada_log("has regexp groups: ", has_regexp_groups); |
| 9116 | |
| 9117 | // Return a new component whose pattern string is pattern string, regular |
| 9118 | // expression is regular expression, group name list is name list, and has |
| 9119 | // regexp groups is has regexp groups. |
| 9120 | return url_pattern_component<regex_provider>( |
| 9121 | std::move(pattern_string), std::move(*regular_expression), |
| 9122 | std::move(name_list), has_regexp_groups); |
| 9123 | } |
| 9124 | |
| 9125 | template <url_pattern_regex::regex_concept regex_provider> |
| 9126 | result<std::optional<url_pattern_result>> url_pattern<regex_provider>::exec( |
no test coverage detected