Skip to content

[libc++] Fix regex_search to match $ alone with match_default flag #78845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libcxx/include/regex
Original file line number Diff line number Diff line change
Expand Up @@ -5124,6 +5124,14 @@ bool basic_regex<_CharT, _Traits>::__search(
}
__m.__matches_.assign(__m.size(), __m.__unmatched_);
}
__m.__matches_.assign(__m.size(), __m.__unmatched_);
if (__match_at_start(__first, __last, __m, __flags, false)) {
__m.__prefix_.second = __m[0].first;
__m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
__m.__suffix_.first = __m[0].second;
__m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
return true;
}
}
__m.__matches_.clear();
return false;
Expand Down
39 changes: 39 additions & 0 deletions libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,44 @@ int main(int, char**)
assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
}

{
std::string target = "foo";
std::regex re("$");
assert(std::regex_search(target, re));
assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));

std::smatch match;
assert(std::regex_search(target, match, re));
assert(match.position(0) == 3);
assert(match.length(0) == 0);
assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));
assert(match.length(0) == 0);
}

{
std::string target = "foo";
std::regex re("$", std::regex::multiline);
std::smatch match;
assert(std::regex_search(target, match, re));
assert(match.position(0) == 3);
assert(match.length(0) == 0);
assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));
assert(match.length(0) == 0);
}

{
std::string target = "foo";
std::regex re("$");
assert(!std::regex_match(target, re));
assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));
}

{
std::string target = "a";
std::regex re("^b*$");
assert(!std::regex_search(target, re));
assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
}

return 0;
}