diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 80243608..77f1bd2e 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -189,28 +189,16 @@ private: return {}; } - bool accept(StringView expected) - { - auto it = m_pos.base(); - for (auto expected_it = expected.begin(); expected_it != expected.end(); ++expected_it) - { - if (it == m_regex.end() or *it++ != *expected_it) - return false; - } - m_pos = Iterator{it, m_regex}; - return true; - } - bool modifiers() { - if (accept("(?i)")) + auto it = m_pos.base(); + if (m_regex.end() - it >= 4 and *it++ == '(' and *it++ == '?') { - m_ignore_case = true; - return true; - } - if (accept("(?I)")) - { - m_ignore_case = false; + auto m = *it++; + if ((m != 'i' and m != 'I') or *it++ != ')') + return false; + m_ignore_case = (m == 'i'); + m_pos = Iterator{it, m_regex}; return true; } return false; @@ -239,25 +227,29 @@ private: break; case '(': { - Optional lookaround_op; - constexpr struct { StringView prefix; ParsedRegex::Op op; } lookarounds[] = { - { "(?=", ParsedRegex::LookAhead }, - { "(?!", ParsedRegex::NegativeLookAhead }, - { "(?<=", ParsedRegex::LookBehind }, - { "(?= 2 and *it++ == '?' and *it++ == ':') + { + m_pos = Iterator{it, m_regex}; + return false; + } + return true; + }; + NodeIndex content = disjunction(captures() ? m_parsed_regex.capture_count++ : -1); if (at_end() or *m_pos++ != ')') parse_error("unclosed parenthesis"); return content;