1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 12:48:11 +00:00

LibWeb: Use ComponentValue::is_ident("..."sv) helper

This commit is contained in:
Sam Atkins 2023-11-21 12:08:39 +00:00 committed by Andreas Kling
parent 6cd6186399
commit f69d38a346
4 changed files with 18 additions and 31 deletions

View file

@ -497,7 +497,7 @@ RefPtr<StyleValue> Parser::parse_radial_gradient_function(ComponentValue const&
return nullptr; return nullptr;
auto& token = tokens.peek_token(); auto& token = tokens.peek_token();
if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("at"sv)) { if (token.is_ident("at"sv)) {
(void)tokens.next_token(); (void)tokens.next_token();
auto position = parse_position_value(tokens); auto position = parse_position_value(tokens);
if (!position) if (!position)

View file

@ -114,7 +114,7 @@ NonnullRefPtr<MediaQuery> Parser::parse_media_query(TokenStream<ComponentValue>&
return media_query; return media_query;
// `[ and <media-condition-without-or> ]?` // `[ and <media-condition-without-or> ]?`
if (auto maybe_and = tokens.next_token(); maybe_and.is(Token::Type::Ident) && maybe_and.token().ident().equals_ignoring_ascii_case("and"sv)) { if (auto maybe_and = tokens.next_token(); maybe_and.is_ident("and"sv)) {
if (auto media_condition = parse_media_condition(tokens, MediaCondition::AllowOr::No)) { if (auto media_condition = parse_media_condition(tokens, MediaCondition::AllowOr::No)) {
tokens.skip_whitespace(); tokens.skip_whitespace();
if (tokens.has_next_token()) if (tokens.has_next_token())
@ -143,7 +143,7 @@ OwnPtr<MediaCondition> Parser::parse_media_condition(TokenStream<ComponentValue>
tokens.skip_whitespace(); tokens.skip_whitespace();
auto& first_token = tokens.next_token(); auto& first_token = tokens.next_token();
if (first_token.is(Token::Type::Ident) && first_token.token().ident().equals_ignoring_ascii_case("not"sv)) { if (first_token.is_ident("not"sv)) {
if (auto child_condition = parse_media_condition(tokens, MediaCondition::AllowOr::Yes)) { if (auto child_condition = parse_media_condition(tokens, MediaCondition::AllowOr::Yes)) {
local_transaction.commit(); local_transaction.commit();
return MediaCondition::from_not(child_condition.release_nonnull()); return MediaCondition::from_not(child_condition.release_nonnull());
@ -158,7 +158,7 @@ OwnPtr<MediaCondition> Parser::parse_media_condition(TokenStream<ComponentValue>
tokens.skip_whitespace(); tokens.skip_whitespace();
auto& first = tokens.next_token(); auto& first = tokens.next_token();
if (first.is(Token::Type::Ident) && first.token().ident().equals_ignoring_ascii_case(combinator)) { if (first.is_ident(combinator)) {
tokens.skip_whitespace(); tokens.skip_whitespace();
if (auto media_in_parens = parse_media_in_parens(tokens)) { if (auto media_in_parens = parse_media_in_parens(tokens)) {
local_transaction.commit(); local_transaction.commit();

View file

@ -176,7 +176,7 @@ OwnPtr<Supports::Condition> Parser::parse_supports_condition(TokenStream<Compone
auto const& peeked_token = tokens.peek_token(); auto const& peeked_token = tokens.peek_token();
// `not <supports-in-parens>` // `not <supports-in-parens>`
if (peeked_token.is(Token::Type::Ident) && peeked_token.token().ident().equals_ignoring_ascii_case("not"sv)) { if (peeked_token.is_ident("not"sv)) {
tokens.next_token(); tokens.next_token();
tokens.skip_whitespace(); tokens.skip_whitespace();
auto child = parse_supports_in_parens(tokens); auto child = parse_supports_in_parens(tokens);
@ -788,7 +788,7 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& tokens)
Optional<size_t> important_index; Optional<size_t> important_index;
for (size_t i = declaration_values.size() - 1; i > 0; i--) { for (size_t i = declaration_values.size() - 1; i > 0; i--) {
auto value = declaration_values[i]; auto value = declaration_values[i];
if (value.is(Token::Type::Ident) && Infra::is_ascii_case_insensitive_match(value.token().ident(), "important"sv)) { if (value.is_ident("important"sv)) {
important_index = i; important_index = i;
break; break;
} }
@ -1578,7 +1578,7 @@ Optional<Dimension> Parser::parse_dimension(ComponentValue const& component_valu
Optional<LengthOrCalculated> Parser::parse_source_size_value(ComponentValue const& component_value) Optional<LengthOrCalculated> Parser::parse_source_size_value(ComponentValue const& component_value)
{ {
if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_ascii_case("auto"sv)) { if (component_value.is_ident("auto"sv)) {
return LengthOrCalculated { Length::make_auto() }; return LengthOrCalculated { Length::make_auto() };
} }
@ -1689,7 +1689,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
// All options start with 'u'/'U'. // All options start with 'u'/'U'.
auto const& u = tokens.next_token(); auto const& u = tokens.next_token();
if (!(u.is(Token::Type::Ident) && u.token().ident().equals_ignoring_ascii_case("u"sv))) { if (!u.is_ident("u"sv)) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: <urange> does not start with 'u'"); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: <urange> does not start with 'u'");
return {}; return {};
} }
@ -3371,8 +3371,7 @@ RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<ComponentValue>
continue; continue;
} }
if (allow_inset_keyword == AllowInsetKeyword::Yes if (allow_inset_keyword == AllowInsetKeyword::Yes && token.is_ident("inset"sv)) {
&& token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("inset"sv)) {
if (placement.has_value()) if (placement.has_value())
return nullptr; return nullptr;
placement = ShadowPlacement::Inner; placement = ShadowPlacement::Inner;
@ -3946,7 +3945,7 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
while (tokens.has_next_token()) { while (tokens.has_next_token()) {
auto& peek_token = tokens.peek_token(); auto& peek_token = tokens.peek_token();
if (peek_token.is(Token::Type::Ident) && value_id_from_string(peek_token.token().ident()) == ValueID::Normal) { if (peek_token.is_ident("normal"sv)) {
normal_count++; normal_count++;
(void)tokens.next_token(); (void)tokens.next_token();
continue; continue;
@ -4337,7 +4336,7 @@ RefPtr<StyleValue> Parser::parse_list_style_value(Vector<ComponentValue> const&
auto tokens = TokenStream { component_values }; auto tokens = TokenStream { component_values };
while (tokens.has_next_token()) { while (tokens.has_next_token()) {
if (auto peek = tokens.peek_token(); peek.is(Token::Type::Ident) && peek.token().ident().equals_ignoring_ascii_case("none"sv)) { if (auto peek = tokens.peek_token(); peek.is_ident("none"sv)) {
(void)tokens.next_token(); (void)tokens.next_token();
found_nones++; found_nones++;
continue; continue;
@ -4779,7 +4778,7 @@ RefPtr<StyleValue> Parser::parse_transform_value(Vector<ComponentValue> const& c
tokens.skip_whitespace(); tokens.skip_whitespace();
auto const& part = tokens.next_token(); auto const& part = tokens.next_token();
if (part.is(Token::Type::Ident) && part.token().ident().equals_ignoring_ascii_case("none"sv)) { if (part.is_ident("none"sv)) {
if (!transformations.is_empty()) if (!transformations.is_empty())
return nullptr; return nullptr;
tokens.skip_whitespace(); tokens.skip_whitespace();
@ -5206,7 +5205,7 @@ Optional<CSS::ExplicitGridTrack> Parser::parse_track_sizing_function(ComponentVa
return CSS::ExplicitGridTrack(GridSize(LengthPercentage(maybe_calculated.release_nonnull()))); return CSS::ExplicitGridTrack(GridSize(LengthPercentage(maybe_calculated.release_nonnull())));
} }
return {}; return {};
} else if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_ascii_case("auto"sv)) { } else if (token.is_ident("auto"sv)) {
return CSS::ExplicitGridTrack(GridSize(Length::make_auto())); return CSS::ExplicitGridTrack(GridSize(Length::make_auto()));
} else if (token.is_block()) { } else if (token.is_block()) {
return {}; return {};

View file

@ -439,7 +439,7 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec
// Parse the `of <selector-list>` syntax // Parse the `of <selector-list>` syntax
auto const& maybe_of = tokens.next_token(); auto const& maybe_of = tokens.next_token();
if (!(maybe_of.is(Token::Type::Ident) && maybe_of.token().ident().equals_ignoring_ascii_case("of"sv))) if (!maybe_of.is_ident("of"sv))
return ParseError::SyntaxError; return ParseError::SyntaxError;
tokens.skip_whitespace(); tokens.skip_whitespace();
@ -678,18 +678,6 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
return {}; return {};
}; };
auto is_n = [](ComponentValue const& value) -> bool {
return value.is(Token::Type::Ident) && value.token().ident().equals_ignoring_ascii_case("n"sv);
};
auto is_ndash = [](ComponentValue const& value) -> bool {
return value.is(Token::Type::Ident) && value.token().ident().equals_ignoring_ascii_case("n-"sv);
};
auto is_dashn = [](ComponentValue const& value) -> bool {
return value.is(Token::Type::Ident) && value.token().ident().equals_ignoring_ascii_case("-n"sv);
};
auto is_dashndash = [](ComponentValue const& value) -> bool {
return value.is(Token::Type::Ident) && value.token().ident().equals_ignoring_ascii_case("-n-"sv);
};
auto is_sign = [](ComponentValue const& value) -> bool { auto is_sign = [](ComponentValue const& value) -> bool {
return value.is(Token::Type::Delim) && (value.token().delim() == '+' || value.token().delim() == '-'); return value.is(Token::Type::Delim) && (value.token().delim() == '+' || value.token().delim() == '-');
}; };
@ -855,7 +843,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
// -n // -n
// -n <signed-integer> // -n <signed-integer>
// -n ['+' | '-'] <signless-integer> // -n ['+' | '-'] <signless-integer>
if (is_dashn(first_value)) { if (first_value.is_ident("-n"sv)) {
values.skip_whitespace(); values.skip_whitespace();
// -n <signed-integer> // -n <signed-integer>
@ -884,7 +872,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
return Selector::SimpleSelector::ANPlusBPattern { -1, 0 }; return Selector::SimpleSelector::ANPlusBPattern { -1, 0 };
} }
// -n- <signless-integer> // -n- <signless-integer>
if (is_dashndash(first_value)) { if (first_value.is_ident("-n-"sv)) {
values.skip_whitespace(); values.skip_whitespace();
auto const& second_value = values.next_token(); auto const& second_value = values.next_token();
if (is_signless_integer(second_value)) { if (is_signless_integer(second_value)) {
@ -913,7 +901,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
// '+'?† n // '+'?† n
// '+'?† n <signed-integer> // '+'?† n <signed-integer>
// '+'?† n ['+' | '-'] <signless-integer> // '+'?† n ['+' | '-'] <signless-integer>
if (is_n(first_after_plus)) { if (first_after_plus.is_ident("n"sv)) {
values.skip_whitespace(); values.skip_whitespace();
// '+'?† n <signed-integer> // '+'?† n <signed-integer>
@ -943,7 +931,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
} }
// '+'?† n- <signless-integer> // '+'?† n- <signless-integer>
if (is_ndash(first_after_plus)) { if (first_after_plus.is_ident("n-"sv)) {
values.skip_whitespace(); values.skip_whitespace();
auto const& second_value = values.next_token(); auto const& second_value = values.next_token();
if (is_signless_integer(second_value)) { if (is_signless_integer(second_value)) {