Skip to content

Commit

Permalink
LibRegex: Do not attempt to find more matches when one match is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard authored and linusg committed Apr 23, 2021
1 parent 2ef5b13 commit bb40d4d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Userland/Libraries/LibRegex/RegexMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ RegexResult Matcher<Parser>::match(const Vector<RegexStringView> views, Optional
auto view_length = view.length();
size_t view_index = m_pattern.start_offset;
state.string_position = view_index;
bool succeeded = false;

if (view_index == view_length && m_pattern.parser_result.match_length_minimum == 0) {
// Run the code until it tries to consume something.
Expand Down Expand Up @@ -182,6 +183,7 @@ RegexResult Matcher<Parser>::match(const Vector<RegexStringView> views, Optional
return { false, 0, {}, {}, {}, output.operations };

if (success.value()) {
succeeded = true;

if (input.regex_options.has_flag_set(AllFlags::MatchNotEndOfLine) && state.string_position == input.view.length()) {
if (!continue_search)
Expand Down Expand Up @@ -229,6 +231,9 @@ RegexResult Matcher<Parser>::match(const Vector<RegexStringView> views, Optional

if (input.regex_options.has_flag_set(AllFlags::Internal_Stateful))
m_pattern.start_offset = state.string_position;

if (succeeded && !continue_search)
break;
}

MatchOutput output_copy;
Expand Down

0 comments on commit bb40d4d

Please sign in to comment.