1#if ADA_INCLUDE_URL_PATTERN
5namespace ada::url_pattern_regex {
7#ifdef ADA_USE_UNSAFE_STD_REGEX_PROVIDER
8std::optional<std::regex> std_regex_provider::create_instance(
9 std::string_view pattern,
bool ignore_case) {
13 auto flags = ignore_case
14 ? std::regex::icase | std::regex_constants::ECMAScript
15 : std::regex_constants::ECMAScript;
17 return std::regex(pattern.data(), pattern.size(), flags);
18 }
catch (
const std::regex_error& e) {
20 ada_log(
"std_regex_provider::create_instance failed:", e.what());
25std::optional<std::vector<std::optional<std::string>>>
26std_regex_provider::regex_search(std::string_view input,
27 const std::regex& pattern) {
29 std::match_results<std::string_view::const_iterator> match_result;
30 if (!std::regex_search(input.begin(), input.end(), match_result, pattern,
31 std::regex_constants::match_any)) {
34 std::vector<std::optional<std::string>> matches;
36 if (input.empty() || match_result.empty()) {
39 matches.reserve(match_result.size());
40 for (
size_t i = 1; i < match_result.size(); ++i) {
41 if (
auto entry = match_result[i]; entry.matched) {
42 matches.emplace_back(entry.str());
48bool std_regex_provider::regex_match(std::string_view input,
49 const std::regex& pattern) {
50 return std::regex_match(input.begin(), input.end(), pattern);