Skip to content

Commit

Permalink
simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Jan 20, 2025
1 parent 8c8b6fc commit 8087c1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/ada/url_pattern_regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concept regex_concept = requires(T t, std::string_view pattern,
// Function to perform regex search
{
t.regex_search(input, std::declval<typename T::regex_type&>())
} -> std::same_as<std::optional<std::vector<std::string>>>;
} -> std::same_as<std::vector<std::string>>;

// Function to match regex pattern
{
Expand All @@ -44,7 +44,7 @@ class std_regex_provider {
using regex_type = std::regex;
static std::optional<regex_type> create_instance(std::string_view pattern,
bool ignore_case);
std::optional<std::vector<std::string>> regex_search(
std::vector<std::string> regex_search(
std::string_view input, const regex_type& pattern);
bool regex_match(std::string_view input, const regex_type& pattern);
};
Expand Down
15 changes: 11 additions & 4 deletions src/url_pattern_regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ std::optional<std::regex> std_regex_provider::create_instance(
}
}

std::optional<std::vector<std::string>> std_regex_provider::regex_search(
std::vector<std::string> std_regex_provider::regex_search(
std::string_view input, const std::regex& pattern) {
(void)input;
(void)pattern;
return {};

std::vector<std::string> matches;
std::string input_str(input.begin(), input.end()); // Convert string_view to string for regex_search
std::smatch match_result;

while (std::regex_search(input_str, match_result, pattern)) {
matches.push_back(match_result.str());
input_str = match_result.suffix().str();
}
return matches;
}

bool std_regex_provider::regex_match(std::string_view input,
Expand Down

0 comments on commit 8087c1d

Please sign in to comment.