1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibWeb: Port CSS Parser from DeprecatedString

These are the last instances of DeprecatedString in the CSS folder.
This commit is contained in:
Shannon Booth 2023-12-03 08:18:43 +13:00 committed by Andreas Kling
parent 2cf3819caf
commit 89bbf53745

View file

@ -2175,7 +2175,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
return color;
} else if (component_value.is(Token::Type::Hash)) {
auto color = Color::from_string(DeprecatedString::formatted("#{}", component_value.token().hash_value()));
auto color = Color::from_string(MUST(String::formatted("#{}", component_value.token().hash_value())));
if (color.has_value())
return color;
return {};
@ -2194,7 +2194,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
// 1. Let cv be the component value.
auto const& cv = component_value;
DeprecatedString serialization;
String serialization;
// 2. If cv is a <number-token> or a <dimension-token>, follow these substeps:
if (cv.is(Token::Type::Number) || cv.is(Token::Type::Dimension)) {
// 1. If cvs type flag is not "integer", return an error.
@ -2216,35 +2216,34 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
serialization_builder.append(cv.token().dimension_unit());
// 5. If serialization consists of fewer than six characters, prepend zeros (U+0030) so that it becomes six characters.
serialization = serialization_builder.to_deprecated_string();
serialization = MUST(serialization_builder.to_string());
if (serialization_builder.length() < 6) {
StringBuilder builder;
for (size_t i = 0; i < (6 - serialization_builder.length()); i++)
builder.append('0');
builder.append(serialization_builder.string_view());
serialization = builder.to_deprecated_string();
serialization = MUST(builder.to_string());
}
}
// 3. Otherwise, cv is an <ident-token>; let serialization be cvs value.
else {
if (!cv.is(Token::Type::Ident))
return {};
serialization = cv.token().ident().bytes_as_string_view();
serialization = cv.token().ident().to_string();
}
// 4. If serialization does not consist of three or six characters, return an error.
if (serialization.length() != 3 && serialization.length() != 6)
if (serialization.bytes().size() != 3 && serialization.bytes().size() != 6)
return {};
// 5. If serialization contains any characters not in the range [0-9A-Fa-f] (U+0030 to U+0039, U+0041 to U+0046, U+0061 to U+0066), return an error.
for (auto c : serialization) {
for (auto c : serialization.bytes_as_string_view()) {
if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')))
return {};
}
// 6. Return the concatenation of "#" (U+0023) and serialization.
DeprecatedString concatenation = DeprecatedString::formatted("#{}", serialization);
return Color::from_string(concatenation);
return Color::from_string(MUST(String::formatted("#{}", serialization)));
}
return {};
@ -4044,7 +4043,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>&
// font-family: my cool font\!, serif;
// font-family: "my cool font!", serif;
StyleValueVector font_families;
Vector<DeprecatedString> current_name_parts;
Vector<String> current_name_parts;
while (tokens.has_next_token()) {
auto const& peek = tokens.peek_token();
@ -4079,7 +4078,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>&
(void)tokens.next_token(); // Comma
continue;
}
current_name_parts.append(tokens.next_token().token().ident().bytes_as_string_view());
current_name_parts.append(tokens.next_token().token().ident().to_string());
continue;
}