From 2ef5658f31ba83cee70dc18e601e154fcc38bfef Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 5 Sep 2023 19:42:28 +0100 Subject: [PATCH] LibWeb: Add ComponentValue::is_function(name) and is_ident(name) helpers --- .../Libraries/LibWeb/CSS/Parser/ComponentValue.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp index 90ab1e02b0..b8d30eed8b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp @@ -26,6 +26,16 @@ ComponentValue::ComponentValue(NonnullRefPtr block) ComponentValue::~ComponentValue() = default; +bool ComponentValue::is_function(StringView name) const +{ + return is_function() && function().name().equals_ignoring_ascii_case(name); +} + +bool ComponentValue::is_ident(StringView ident) const +{ + return is(Token::Type::Ident) && token().ident().equals_ignoring_ascii_case(ident); +} + String ComponentValue::to_string() const { return m_value.visit( diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h index 069472f7db..dfe502233e 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h @@ -27,11 +27,13 @@ public: Block& block() const { return m_value.get>(); } bool is_function() const { return m_value.has>(); } + bool is_function(StringView name) const; Function& function() const { return m_value.get>(); } bool is_token() const { return m_value.has(); } bool is(Token::Type type) const { return is_token() && token().is(type); } bool is_delim(u32 delim) const { return is(Token::Type::Delim) && token().delim() == delim; } + bool is_ident(StringView ident) const; Token const& token() const { return m_value.get(); } operator Token() const { return m_value.get(); }