LibWeb: Parse quotes property using TokenStream

This commit is contained in:
Sam Atkins 2023-12-07 12:38:51 +00:00 committed by Sam Atkins
parent ebad94658a
commit 647d52ff9a
Notes: sideshowbarker 2024-07-17 07:08:37 +09:00
2 changed files with 11 additions and 8 deletions

View File

@ -4579,23 +4579,25 @@ RefPtr<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const&
{ *maybe_align_self_value, *maybe_justify_self_value });
}
RefPtr<StyleValue> Parser::parse_quotes_value(Vector<ComponentValue> const& component_values)
RefPtr<StyleValue> Parser::parse_quotes_value(TokenStream<ComponentValue>& tokens)
{
// https://www.w3.org/TR/css-content-3/#quotes-property
// auto | none | [ <string> <string> ]+
auto transaction = tokens.begin_transaction();
if (component_values.size() == 1) {
auto identifier = parse_identifier_value(component_values.first());
if (identifier && property_accepts_identifier(PropertyID::Quotes, identifier->to_identifier()))
if (tokens.remaining_token_count() == 1) {
auto identifier = parse_identifier_value(tokens.next_token());
if (identifier && property_accepts_identifier(PropertyID::Quotes, identifier->to_identifier())) {
transaction.commit();
return identifier;
}
return nullptr;
}
// Parse an even number of <string> values.
if (component_values.size() % 2 != 0)
if (tokens.remaining_token_count() % 2 != 0)
return nullptr;
auto tokens = TokenStream { component_values };
StyleValueVector string_values;
while (tokens.has_next_token()) {
auto maybe_string = parse_string_value(tokens.next_token());
@ -4605,6 +4607,7 @@ RefPtr<StyleValue> Parser::parse_quotes_value(Vector<ComponentValue> const& comp
string_values.append(maybe_string.release_nonnull());
}
transaction.commit();
return StyleValueList::create(move(string_values), StyleValueList::Separator::Space);
}
@ -5893,7 +5896,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::Quotes:
if (auto parsed_value = parse_quotes_value(component_values))
if (auto parsed_value = parse_quotes_value(tokens); parsed_value && !tokens.has_next_token())
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::TextDecoration:

View File

@ -245,7 +245,7 @@ private:
RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_quotes_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_quotes_value(TokenStream<ComponentValue>&);
enum class AllowInsetKeyword {
No,
Yes,