diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-07-01 14:52:12 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 23:19:56 +0200 |
commit | f7c79de0c504c54ae482e4b57921b5c69172e905 (patch) | |
tree | 9515122b3e6d895bc1e760cfd575c4959e0976a7 | |
parent | d6b4022b58b1bbbd28c54484dc1a04475648ac25 (diff) | |
download | serenity-f7c79de0c504c54ae482e4b57921b5c69172e905.zip |
LibWeb: Add convenience methods to CSS::Parser::Token
Some of these will be removed later, when we move to using is()
exclusively.
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Token.h | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Token.h b/Userland/Libraries/LibWeb/CSS/Parser/Token.h index e9c55971fd..3d02cc0c2b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Token.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Token.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -56,22 +57,50 @@ public: }; bool is_eof() const { return m_type == TokenType::EndOfFile; } + bool is_ident() const { return m_type == TokenType::Ident; } + bool is_function() const { return m_type == TokenType::Function; } + bool is_at() const { return m_type == TokenType::AtKeyword; } + bool is_hash() const { return m_type == TokenType::Hash; } + bool is_string() const { return m_type == TokenType::String; } + bool is_bad_string() const { return m_type == TokenType::BadString; } + bool is_url() const { return m_type == TokenType::Url; } + bool is_bad_url() const { return m_type == TokenType::BadUrl; } + bool is_delim() const { return m_type == TokenType::Delim; } + bool is_number() const { return m_type == TokenType::Number; } + bool is_percentage() const { return m_type == TokenType::Percentage; } + bool is_dimension() const { return m_type == TokenType::Dimension; } bool is_whitespace() const { return m_type == TokenType::Whitespace; } bool is_cdo() const { return m_type == TokenType::CDO; } bool is_cdc() const { return m_type == TokenType::CDC; } - bool is_at() const { return m_type == TokenType::AtKeyword; } + bool is_colon() const { return m_type == TokenType::Colon; } bool is_semicolon() const { return m_type == TokenType::Semicolon; } - bool is_open_curly() const { return m_type == TokenType::OpenCurly; } + bool is_comma() const { return m_type == TokenType::Comma; } bool is_open_square() const { return m_type == TokenType::OpenSquare; } + bool is_close_square() const { return m_type == TokenType::CloseSquare; } bool is_open_paren() const { return m_type == TokenType::OpenParen; } bool is_close_paren() const { return m_type == TokenType::CloseParen; } - bool is_close_square() const { return m_type == TokenType::CloseSquare; } + bool is_open_curly() const { return m_type == TokenType::OpenCurly; } bool is_close_curly() const { return m_type == TokenType::CloseCurly; } - bool is_function() const { return m_type == TokenType::Function; } - bool is_colon() const { return m_type == TokenType::Colon; } - bool is_ident() const { return m_type == TokenType::Ident; } - bool is_delim() const { return m_type == TokenType::Delim; } - bool is_comma() const { return m_type == TokenType::Comma; } + + bool is(TokenType type) const { return m_type == type; } + + StringView ident() const + { + VERIFY(is_ident()); + return m_value.string_view(); + } + + StringView delim() const + { + VERIFY(is_delim()); + return m_value.string_view(); + } + + StringView string() const + { + VERIFY(is_string()); + return m_value.string_view(); + } TokenType mirror_variant() const; String bracket_string() const; |