diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-24 23:47:22 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-25 13:41:09 +0330 |
commit | 67ce9e28a5f8d800176dd2749f884be8f7f64de2 (patch) | |
tree | 0a753b34c2d7a3dad11097fac81fc4c522fee5e3 /Userland/Libraries/LibCpp | |
parent | d49d2c7ec4cbe2c0792cf112055a6f5eca79dd63 (diff) | |
download | serenity-67ce9e28a5f8d800176dd2749f884be8f7f64de2.zip |
AK: Standardize the behaviour of GenericLexer::consume_until overloads
Before this commit all consume_until overloads aside from the Predicate
one would consume (and ignore) the stop char/string, while the
Predicate overload would not, in order to keep behaviour consistent,
the other overloads no longer consume the stop char/string as well.
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r-- | Userland/Libraries/LibCpp/Preprocessor.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp index f1ade8f27b..5159f5ea6e 100644 --- a/Userland/Libraries/LibCpp/Preprocessor.cpp +++ b/Userland/Libraries/LibCpp/Preprocessor.cpp @@ -94,6 +94,7 @@ void Preprocessor::handle_preprocessor_statement(StringView line) lexer.consume_specific('#'); consume_whitespace(lexer); auto keyword = lexer.consume_until(' '); + lexer.ignore(); if (keyword.is_empty() || keyword.is_null() || keyword.is_whitespace()) return; @@ -165,6 +166,7 @@ void Preprocessor::handle_preprocessor_keyword(StringView keyword, GenericLexer& ++m_current_depth; if (m_state == State::Normal) { auto key = line_lexer.consume_until(' '); + line_lexer.ignore(); if (m_definitions.contains(key)) { m_depths_of_taken_branches.append(m_current_depth - 1); return; @@ -180,6 +182,7 @@ void Preprocessor::handle_preprocessor_keyword(StringView keyword, GenericLexer& ++m_current_depth; if (m_state == State::Normal) { auto key = line_lexer.consume_until(' '); + line_lexer.ignore(); if (!m_definitions.contains(key)) { m_depths_of_taken_branches.append(m_current_depth - 1); return; @@ -353,10 +356,12 @@ Optional<Preprocessor::Definition> Preprocessor::create_definition(StringView li String Preprocessor::remove_escaped_newlines(StringView value) { + static constexpr auto escaped_newline = "\\\n"sv; AK::StringBuilder processed_value; GenericLexer lexer { value }; while (!lexer.is_eof()) { - processed_value.append(lexer.consume_until("\\\n"sv)); + processed_value.append(lexer.consume_until(escaped_newline)); + lexer.ignore(escaped_newline.length()); } return processed_value.to_string(); } |