1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

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.
This commit is contained in:
Idan Horowitz 2022-01-24 23:47:22 +02:00 committed by Ali Mohammad Pur
parent d49d2c7ec4
commit 67ce9e28a5
7 changed files with 18 additions and 14 deletions

View file

@ -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();
}