From e00f41a274a41b9c38639977e7e4c7a7fa86e955 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 27 Dec 2023 12:00:41 +0000 Subject: [PATCH] LibWeb: Parse URL values using TokenStream --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 12 +++++------- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 7eecfad13d6..6ea5f70fd20 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1195,11 +1195,12 @@ Optional Parser::parse_url_function(ComponentValue const& component_va return {}; } -RefPtr Parser::parse_url_value(ComponentValue const& component_value) +RefPtr Parser::parse_url_value(TokenStream& tokens) { - auto url = parse_url_function(component_value); + auto url = parse_url_function(tokens.peek_token()); if (!url.has_value()) return nullptr; + (void)tokens.next_token(); return URLStyleValue::create(*url); } @@ -2585,8 +2586,7 @@ RefPtr Parser::parse_paint_value(TokenStream& tokens if (auto color_or_none = parse_color_or_none(); color_or_none.has_value()) return *color_or_none; - if (auto url = parse_url_value(tokens.peek_token())) { - (void)tokens.next_token(); + if (auto url = parse_url_value(tokens)) { tokens.skip_whitespace(); if (auto color_or_none = parse_color_or_none(); color_or_none == nullptr) { // Fail to parse if the fallback is invalid, but otherwise ignore it. @@ -6561,10 +6561,8 @@ Optional Parser::parse_css_value_for_properties(Readon } if (auto property = any_property_accepts_type(property_ids, ValueType::Url); property.has_value()) { - if (auto url = parse_url_value(peek_token)) { - (void)tokens.next_token(); + if (auto url = parse_url_value(tokens)) return PropertyAndValue { *property, url }; - } } bool property_accepts_dimension = any_property_accepts_type(property_ids, ValueType::Angle).has_value() diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 56a01d873f3..1a8f7ca2d46 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -196,7 +196,7 @@ private: Optional parse_track_sizing_function(ComponentValue const&); Optional parse_url_function(ComponentValue const&); - RefPtr parse_url_value(ComponentValue const&); + RefPtr parse_url_value(TokenStream&); template Optional> parse_color_stop_list(TokenStream& tokens, auto is_position, auto get_position);