1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

LibRegex: Do not return an Optional from Regex::Matcher::execute

The code path that could return an optional no longer exists as of
commit: a962ee020a
This commit is contained in:
Timothy Flynn 2022-02-05 09:24:26 -05:00 committed by Ali Mohammad Pur
parent 27d3de1f17
commit 3729fd06fa
2 changed files with 9 additions and 14 deletions

View file

@ -216,8 +216,7 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
auto success = execute(input, state, temp_operations); auto success = execute(input, state, temp_operations);
// This success is acceptable only if it doesn't read anything from the input (input length is 0). // This success is acceptable only if it doesn't read anything from the input (input length is 0).
if (state.string_position <= view_index) { if (success && (state.string_position <= view_index)) {
if (success.has_value() && success.value()) {
operations = temp_operations; operations = temp_operations;
if (!match_count) { if (!match_count) {
// Nothing was *actually* matched, so append an empty match. // Nothing was *actually* matched, so append an empty match.
@ -226,7 +225,6 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
} }
} }
} }
}
for (; view_index <= view_length; ++view_index) { for (; view_index <= view_length; ++view_index) {
if (view_index == view_length && input.regex_options.has_flag_set(AllFlags::Multiline)) if (view_index == view_length && input.regex_options.has_flag_set(AllFlags::Multiline))
@ -251,10 +249,7 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
state.repetition_marks.clear(); state.repetition_marks.clear();
auto success = execute(input, state, operations); auto success = execute(input, state, operations);
if (!success.has_value()) if (success) {
return { false, 0, {}, {}, {}, operations };
if (success.value()) {
succeeded = true; succeeded = true;
if (input.regex_options.has_flag_set(AllFlags::MatchNotEndOfLine) && state.string_position == input.view.length()) { if (input.regex_options.has_flag_set(AllFlags::MatchNotEndOfLine) && state.string_position == input.view.length()) {
@ -417,7 +412,7 @@ private:
}; };
template<class Parser> template<class Parser>
Optional<bool> Matcher<Parser>::execute(MatchInput const& input, MatchState& state, size_t& operations) const bool Matcher<Parser>::execute(MatchInput const& input, MatchState& state, size_t& operations) const
{ {
BumpAllocatedLinkedList<MatchState> states_to_try_next; BumpAllocatedLinkedList<MatchState> states_to_try_next;
size_t recursion_level = 0; size_t recursion_level = 0;

View file

@ -74,7 +74,7 @@ public:
} }
private: private:
Optional<bool> execute(MatchInput const& input, MatchState& state, size_t& operations) const; bool execute(MatchInput const& input, MatchState& state, size_t& operations) const;
Regex<Parser> const* m_pattern; Regex<Parser> const* m_pattern;
typename ParserTraits<Parser>::OptionsType const m_regex_options; typename ParserTraits<Parser>::OptionsType const m_regex_options;