mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:37:43 +00:00
LibWeb: Port CSS Parser from DeprecatedString
These are the last instances of DeprecatedString in the CSS folder.
This commit is contained in:
parent
2cf3819caf
commit
89bbf53745
1 changed files with 10 additions and 11 deletions
|
@ -2175,7 +2175,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
|
||||||
return color;
|
return color;
|
||||||
|
|
||||||
} else if (component_value.is(Token::Type::Hash)) {
|
} 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())
|
if (color.has_value())
|
||||||
return color;
|
return color;
|
||||||
return {};
|
return {};
|
||||||
|
@ -2194,7 +2194,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
|
||||||
|
|
||||||
// 1. Let cv be the component value.
|
// 1. Let cv be the component value.
|
||||||
auto const& cv = 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:
|
// 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)) {
|
if (cv.is(Token::Type::Number) || cv.is(Token::Type::Dimension)) {
|
||||||
// 1. If cv’s type flag is not "integer", return an error.
|
// 1. If cv’s 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());
|
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.
|
// 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) {
|
if (serialization_builder.length() < 6) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (size_t i = 0; i < (6 - serialization_builder.length()); i++)
|
for (size_t i = 0; i < (6 - serialization_builder.length()); i++)
|
||||||
builder.append('0');
|
builder.append('0');
|
||||||
builder.append(serialization_builder.string_view());
|
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 cv’s value.
|
// 3. Otherwise, cv is an <ident-token>; let serialization be cv’s value.
|
||||||
else {
|
else {
|
||||||
if (!cv.is(Token::Type::Ident))
|
if (!cv.is(Token::Type::Ident))
|
||||||
return {};
|
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.
|
// 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 {};
|
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.
|
// 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')))
|
if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')))
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Return the concatenation of "#" (U+0023) and serialization.
|
// 6. Return the concatenation of "#" (U+0023) and serialization.
|
||||||
DeprecatedString concatenation = DeprecatedString::formatted("#{}", serialization);
|
return Color::from_string(MUST(String::formatted("#{}", serialization)));
|
||||||
return Color::from_string(concatenation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
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;
|
||||||
// font-family: "my cool font!", serif;
|
// font-family: "my cool font!", serif;
|
||||||
StyleValueVector font_families;
|
StyleValueVector font_families;
|
||||||
Vector<DeprecatedString> current_name_parts;
|
Vector<String> current_name_parts;
|
||||||
while (tokens.has_next_token()) {
|
while (tokens.has_next_token()) {
|
||||||
auto const& peek = tokens.peek_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
|
(void)tokens.next_token(); // Comma
|
||||||
continue;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue