From 3367815ea118bd1b123068e1e1d84904a66b3576 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 7 Jan 2025 15:34:43 -0500 Subject: [PATCH] add half-working match_result --- include/ada/url_pattern-inl.h | 20 +++++++++++--------- src/url_pattern.cpp | 18 +++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/ada/url_pattern-inl.h b/include/ada/url_pattern-inl.h index c5fa65400..8d0970964 100644 --- a/include/ada/url_pattern-inl.h +++ b/include/ada/url_pattern-inl.h @@ -46,19 +46,21 @@ url_pattern_component::create_component_match_result( // Optimization: Let's reserve the size. result.groups.reserve(exec_result.size() - 1); - // Let index be 0. + size_t group_index = 0; + // Let index be 1. // While index is less than Get(execResult, "length"): - for (size_t index = 0; index < exec_result.size() - 1; index++) { - // Let name be component’s group name list[index]. + for (size_t index = 1; index < exec_result.size(); index++) { + // Let name be component’s group name list[index - 1]. // Let value be Get(execResult, ToString(index)). // Set groups[name] to value. auto match = exec_result[index]; - if (auto str = match.str(); !str.empty()) { - result.groups.insert({ - group_name_list[index], - str, - }); - } + if (!match.matched || match.length() == 0) continue; + result.groups.insert({ + group_name_list[group_index], + match.str(), + }); + + group_index++; } return result; } diff --git a/src/url_pattern.cpp b/src/url_pattern.cpp index 666c764ee..d5d9f4eb4 100644 --- a/src/url_pattern.cpp +++ b/src/url_pattern.cpp @@ -681,59 +681,59 @@ result> url_pattern::match( } } - auto regex_flags = std::regex_constants::match_any; + auto regex_flags = std::regex_constants::match_continuous; // Let protocolExecResult be RegExpBuiltinExec(urlPattern’s protocol // component's regular expression, protocol). std::smatch protocol_exec_result_value; auto protocol_exec_result = - std::regex_match(protocol, protocol_exec_result_value, + std::regex_search(protocol, protocol_exec_result_value, protocol_component.regexp, regex_flags); // Let usernameExecResult be RegExpBuiltinExec(urlPattern’s username // component's regular expression, username). std::smatch username_exec_result_value; auto username_exec_result = - std::regex_match(username, username_exec_result_value, + std::regex_search(username, username_exec_result_value, username_component.regexp, regex_flags); // Let passwordExecResult be RegExpBuiltinExec(urlPattern’s password // component's regular expression, password). std::smatch password_exec_result_value; auto password_exec_result = - std::regex_match(password, password_exec_result_value, + std::regex_search(password, password_exec_result_value, password_component.regexp, regex_flags); // Let hostnameExecResult be RegExpBuiltinExec(urlPattern’s hostname // component's regular expression, hostname). std::smatch hostname_exec_result_value; auto hostname_exec_result = - std::regex_match(hostname, hostname_exec_result_value, + std::regex_search(hostname, hostname_exec_result_value, hostname_component.regexp, regex_flags); // Let portExecResult be RegExpBuiltinExec(urlPattern’s port component's // regular expression, port). std::smatch port_exec_result_value; - auto port_exec_result = std::regex_match(port, port_exec_result_value, + auto port_exec_result = std::regex_search(port, port_exec_result_value, port_component.regexp, regex_flags); // Let pathnameExecResult be RegExpBuiltinExec(urlPattern’s pathname // component's regular expression, pathname). std::smatch pathname_exec_result_value; auto pathname_exec_result = - std::regex_match(pathname, pathname_exec_result_value, + std::regex_search(pathname, pathname_exec_result_value, pathname_component.regexp, regex_flags); // Let searchExecResult be RegExpBuiltinExec(urlPattern’s search component's // regular expression, search). std::smatch search_exec_result_value; - auto search_exec_result = std::regex_match( + auto search_exec_result = std::regex_search( search, search_exec_result_value, search_component.regexp, regex_flags); // Let hashExecResult be RegExpBuiltinExec(urlPattern’s hash component's // regular expression, hash). std::smatch hash_exec_result_value; - auto hash_exec_result = std::regex_match(hash, hash_exec_result_value, + auto hash_exec_result = std::regex_search(hash, hash_exec_result_value, hash_component.regexp, regex_flags); // If protocolExecResult, usernameExecResult, passwordExecResult,