diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-07-02 19:52:07 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 23:19:56 +0200 |
commit | 390cc30a9707b36477b1042359249f7e448038c0 (patch) | |
tree | b9ed3c7792d5d979d3238c13d4c9195e59cb0094 /Userland/Libraries/LibWeb/CSS | |
parent | 985ed47a380538dc269379a84893b3e040896eab (diff) | |
download | serenity-390cc30a9707b36477b1042359249f7e448038c0.zip |
LibWeb: Bring CSS::Parser::parse_as_comma_separated_list...() to spec
Previous implementation was returning everything in a single Vector,
when what we really want is a Vector of Vectors, one for each comma-
separated part of the list.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 27 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index debadf3358..2833f12f0d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -833,20 +833,35 @@ Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values() return rules; } -Vector<StyleComponentValueRule> Parser::parse_as_list_of_comma_separated_component_values() +Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values() { - Vector<StyleComponentValueRule> rules; + Vector<Vector<StyleComponentValueRule>> lists; + lists.append({}); for (;;) { - rules.append(consume_a_component_value()); + auto next = next_token(); - if (peek_token().is_comma()) + if (next.is_comma()) { + lists.append({}); continue; - if (peek_token().is_eof()) + } else if (next.is_eof()) { break; + } + + reconsume_current_input_token(); + auto component_value = consume_a_component_value(); + lists.last().append(component_value); } - return rules; + for (auto& list : lists) { + if (!list.is_empty() && list.first().is(Token::TokenType::Whitespace)) + list.take_first(); + + if (!list.is_empty() && list.last().is(Token::TokenType::Whitespace)) + list.take_last(); + } + + return lists; } RefPtr<CSSRule> Parser::convert_rule(NonnullRefPtr<QualifiedStyleRule>) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 67cc146123..0ab9421f37 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -46,7 +46,7 @@ public: // For the contents of presentational attributes, which parse text into a single declaration’s value, or for parsing a stand-alone selector [SELECT] or list of Media Queries [MEDIAQ], as in Selectors API or the media HTML attribute. Vector<StyleComponentValueRule> parse_as_list_of_component_values(); - Vector<StyleComponentValueRule> parse_as_list_of_comma_separated_component_values(); + Vector<Vector<StyleComponentValueRule>> parse_as_comma_separated_list_of_component_values(); Vector<CSS::Selector::ComplexSelector> parse_selectors(Vector<StyleComponentValueRule> parts); |