| 9146 | |
| 9147 | template <url_pattern_regex::regex_concept regex_provider> |
| 9148 | result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match( |
| 9149 | const url_pattern_input& input, const std::string_view* base_url_string) { |
| 9150 | std::string protocol{}; |
| 9151 | std::string username{}; |
| 9152 | std::string password{}; |
| 9153 | std::string hostname{}; |
| 9154 | std::string port{}; |
| 9155 | std::string pathname{}; |
| 9156 | std::string search{}; |
| 9157 | std::string hash{}; |
| 9158 | |
| 9159 | // Let inputs be an empty list. |
| 9160 | // Append input to inputs. |
| 9161 | std::vector inputs{input}; |
| 9162 | |
| 9163 | // If input is a URLPatternInit then: |
| 9164 | if (std::holds_alternative<url_pattern_init>(input)) { |
| 9165 | ada_log( |
| 9166 | "url_pattern::match called with url_pattern_init and base_url_string=", |
| 9167 | base_url_string); |
| 9168 | // If baseURLString was given, throw a TypeError. |
| 9169 | if (base_url_string) { |
| 9170 | ada_log("failed to match because base_url_string was given"); |
| 9171 | return tl::unexpected(errors::type_error); |
| 9172 | } |
| 9173 | |
| 9174 | // Let applyResult be the result of process a URLPatternInit given input, |
| 9175 | // "url", protocol, username, password, hostname, port, pathname, search, |
| 9176 | // and hash. |
| 9177 | auto apply_result = url_pattern_init::process( |
| 9178 | std::get<url_pattern_init>(input), url_pattern_init::process_type::url, |
| 9179 | protocol, username, password, hostname, port, pathname, search, hash); |
| 9180 | |
| 9181 | // If this throws an exception, catch it, and return null. |
| 9182 | if (!apply_result.has_value()) { |
| 9183 | ada_log("match returned std::nullopt because process threw"); |
| 9184 | return std::nullopt; |
| 9185 | } |
| 9186 | |
| 9187 | // Set protocol to applyResult["protocol"]. |
| 9188 | ADA_ASSERT_TRUE(apply_result->protocol.has_value()); |
| 9189 | protocol = std::move(apply_result->protocol.value()); |
| 9190 | |
| 9191 | // Set username to applyResult["username"]. |
| 9192 | ADA_ASSERT_TRUE(apply_result->username.has_value()); |
| 9193 | username = std::move(apply_result->username.value()); |
| 9194 | |
| 9195 | // Set password to applyResult["password"]. |
| 9196 | ADA_ASSERT_TRUE(apply_result->password.has_value()); |
| 9197 | password = std::move(apply_result->password.value()); |
| 9198 | |
| 9199 | // Set hostname to applyResult["hostname"]. |
| 9200 | ADA_ASSERT_TRUE(apply_result->hostname.has_value()); |
| 9201 | hostname = std::move(apply_result->hostname.value()); |
| 9202 | |
| 9203 | // Set port to applyResult["port"]. |
| 9204 | ADA_ASSERT_TRUE(apply_result->port.has_value()); |
| 9205 | port = std::move(apply_result->port.value()); |
no test coverage detected