Skip to content

Commit

Permalink
add half-working match_result
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 7, 2025
1 parent f75ed01 commit 3367815
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
20 changes: 11 additions & 9 deletions include/ada/url_pattern-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions src/url_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,59 +681,59 @@ result<std::optional<url_pattern_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,
Expand Down

0 comments on commit 3367815

Please sign in to comment.