diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-21 16:53:49 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-23 19:07:44 +0200 |
commit | 9a2eecaca4829aa623d33931a47872888541608e (patch) | |
tree | fb8576e226cb06ff98f27c9f16b4d2fe40dc1661 /Userland/Libraries/LibWeb/CSS/Parser | |
parent | dfbdc20f872b01449405aa9c4f6ac0c22415368b (diff) | |
download | serenity-9a2eecaca4829aa623d33931a47872888541608e.zip |
LibWeb: Add CSS Tokenizer::consume_as_much_whitespace_as_possible()
This is a step in the spec in 3 places, and we had it implemented
differently in each one. This unifies them and makes it clearer what
we're doing.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Parser')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h | 1 |
2 files changed, 12 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp index 09ae068554..ad6a52bc29 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp @@ -490,13 +490,7 @@ String Tokenizer::consume_a_name() Token Tokenizer::consume_a_url_token() { auto token = create_new_token(Token::Type::Url); - for (;;) { - if (!is_whitespace(peek_code_point())) { - break; - } - - (void)next_code_point(); - } + consume_as_much_whitespace_as_possible(); for (;;) { @@ -512,13 +506,8 @@ Token Tokenizer::consume_a_url_token() } if (is_whitespace(input)) { - for (;;) { - if (!is_whitespace(peek_code_point())) { - break; - } - - input = next_code_point(); - } + consume_as_much_whitespace_as_possible(); + input = peek_code_point(); if (is_eof(input)) { log_parse_error(); @@ -580,6 +569,13 @@ void Tokenizer::consume_the_remnants_of_a_bad_url() } } +void Tokenizer::consume_as_much_whitespace_as_possible() +{ + while (is_whitespace(peek_code_point())) { + (void)next_code_point(); + } +} + void Tokenizer::reconsume_current_input_code_point() { m_utf8_iterator = m_prev_utf8_iterator; @@ -763,13 +759,7 @@ Token Tokenizer::consume_a_token() if (is_whitespace(input)) { dbgln_if(CSS_TOKENIZER_DEBUG, "is whitespace"); - - auto next = peek_code_point(); - while (is_whitespace(next)) { - (void)next_code_point(); - next = peek_code_point(); - } - + consume_as_much_whitespace_as_possible(); return create_new_token(Token::Type::Whitespace); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h index b5f38e5fe8..a5198bbd4f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h @@ -91,6 +91,7 @@ private: [[nodiscard]] Token consume_a_url_token(); void consume_the_remnants_of_a_bad_url(); void consume_comments(); + void consume_as_much_whitespace_as_possible(); void reconsume_current_input_code_point(); [[nodiscard]] static bool is_valid_escape_sequence(U32Twin); [[nodiscard]] bool would_start_an_identifier(); |