diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-04-23 03:54:26 +0430 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-23 10:05:04 +0200 |
commit | bb40d4d5fff1ca729c14171561d03621d765854e (patch) | |
tree | b16a4b5e45725df34bb8184bb7f6ca3a34ece02e /Userland | |
parent | 2ef5b138ee306f9df099d4ea795b15dea3d43aa7 (diff) | |
download | serenity-bb40d4d5fff1ca729c14171561d03621d765854e.zip |
LibRegex: Do not attempt to find more matches when one match is needed
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibRegex/RegexMatcher.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Userland/Libraries/LibRegex/RegexMatcher.cpp b/Userland/Libraries/LibRegex/RegexMatcher.cpp index 4a1675e516..c5e481b4d9 100644 --- a/Userland/Libraries/LibRegex/RegexMatcher.cpp +++ b/Userland/Libraries/LibRegex/RegexMatcher.cpp @@ -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. @@ -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) @@ -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; |