mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibWeb: Return FlyString const& from CSS::Parser::Token
This allows us to not need to convert back to a FlyString when we need one.
This commit is contained in:
parent
b9902fef36
commit
6813dcaff8
3 changed files with 21 additions and 21 deletions
|
@ -1152,7 +1152,7 @@ Optional<AK::URL> Parser::parse_url_function(ComponentValue const& component_val
|
||||||
{
|
{
|
||||||
// FIXME: Handle list of media queries. https://www.w3.org/TR/css-cascade-3/#conditional-import
|
// FIXME: Handle list of media queries. https://www.w3.org/TR/css-cascade-3/#conditional-import
|
||||||
|
|
||||||
auto convert_string_to_url = [&](StringView& url_string) -> Optional<AK::URL> {
|
auto convert_string_to_url = [&](StringView url_string) -> Optional<AK::URL> {
|
||||||
auto url = m_context.complete_url(url_string);
|
auto url = m_context.complete_url(url_string);
|
||||||
if (url.is_valid())
|
if (url.is_valid())
|
||||||
return url;
|
return url;
|
||||||
|
@ -1367,9 +1367,9 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
||||||
|
|
||||||
FlyString namespace_uri;
|
FlyString namespace_uri;
|
||||||
if (token.is(Token::Type::String)) {
|
if (token.is(Token::Type::String)) {
|
||||||
namespace_uri = MUST(FlyString::from_utf8(token.token().string()));
|
namespace_uri = token.token().string();
|
||||||
} else if (auto url = parse_url_function(token); url.has_value()) {
|
} else if (auto url = parse_url_function(token); url.has_value()) {
|
||||||
namespace_uri = MUST(FlyString::from_deprecated_fly_string(url.value().to_deprecated_string()));
|
namespace_uri = MUST(url.value().to_string());
|
||||||
} else {
|
} else {
|
||||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @namespace rule invalid; discarding.");
|
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @namespace rule invalid; discarding.");
|
||||||
return {};
|
return {};
|
||||||
|
@ -4144,7 +4144,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
|
||||||
if (declaration.name().equals_ignoring_ascii_case("font-family"sv)) {
|
if (declaration.name().equals_ignoring_ascii_case("font-family"sv)) {
|
||||||
// FIXME: This is very similar to, but different from, the logic in parse_font_family_value().
|
// FIXME: This is very similar to, but different from, the logic in parse_font_family_value().
|
||||||
// Ideally they could share code.
|
// Ideally they could share code.
|
||||||
Vector<DeprecatedString> font_family_parts;
|
Vector<FlyString> font_family_parts;
|
||||||
bool had_syntax_error = false;
|
bool had_syntax_error = false;
|
||||||
for (size_t i = 0; i < declaration.values().size(); ++i) {
|
for (size_t i = 0; i < declaration.values().size(); ++i) {
|
||||||
auto const& part = declaration.values()[i];
|
auto const& part = declaration.values()[i];
|
||||||
|
@ -4171,7 +4171,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
|
||||||
had_syntax_error = true;
|
had_syntax_error = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
font_family_parts.append(part.token().ident().bytes_as_string_view());
|
font_family_parts.append(part.token().ident());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -705,10 +705,10 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
||||||
if (!value.token().number().is_integer())
|
if (!value.token().number().is_integer())
|
||||||
return false;
|
return false;
|
||||||
auto dimension_unit = value.token().dimension_unit();
|
auto dimension_unit = value.token().dimension_unit();
|
||||||
if (!dimension_unit.starts_with("n-"sv, CaseSensitivity::CaseInsensitive))
|
if (!dimension_unit.starts_with_bytes("n-"sv, CaseSensitivity::CaseInsensitive))
|
||||||
return false;
|
return false;
|
||||||
for (size_t i = 2; i < dimension_unit.length(); ++i) {
|
for (size_t i = 2; i < dimension_unit.bytes_as_string_view().length(); ++i) {
|
||||||
if (!is_ascii_digit(dimension_unit[i]))
|
if (!is_ascii_digit(dimension_unit.bytes_as_string_view()[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -822,7 +822,7 @@ Optional<Selector::SimpleSelector::ANPlusBPattern> Parser::parse_a_n_plus_b_patt
|
||||||
if (is_ndashdigit_dimension(first_value)) {
|
if (is_ndashdigit_dimension(first_value)) {
|
||||||
auto const& dimension = first_value.token();
|
auto const& dimension = first_value.token();
|
||||||
int a = dimension.dimension_value_int();
|
int a = dimension.dimension_value_int();
|
||||||
auto maybe_b = dimension.dimension_unit().substring_view(1).to_int();
|
auto maybe_b = dimension.dimension_unit().bytes_as_string_view().substring_view(1).to_int();
|
||||||
if (maybe_b.has_value()) {
|
if (maybe_b.has_value()) {
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return Selector::SimpleSelector::ANPlusBPattern { a, maybe_b.value() };
|
return Selector::SimpleSelector::ANPlusBPattern { a, maybe_b.value() };
|
||||||
|
|
|
@ -65,10 +65,10 @@ public:
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView function() const
|
FlyString const& function() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::Function);
|
VERIFY(m_type == Type::Function);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 delim() const
|
u32 delim() const
|
||||||
|
@ -77,22 +77,22 @@ public:
|
||||||
return *Utf8View(m_value.bytes_as_string_view()).begin();
|
return *Utf8View(m_value.bytes_as_string_view()).begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView string() const
|
FlyString const& string() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::String);
|
VERIFY(m_type == Type::String);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView url() const
|
FlyString const& url() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::Url);
|
VERIFY(m_type == Type::Url);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView at_keyword() const
|
FlyString const& at_keyword() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::AtKeyword);
|
VERIFY(m_type == Type::AtKeyword);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashType hash_type() const
|
HashType hash_type() const
|
||||||
|
@ -100,10 +100,10 @@ public:
|
||||||
VERIFY(m_type == Type::Hash);
|
VERIFY(m_type == Type::Hash);
|
||||||
return m_hash_type;
|
return m_hash_type;
|
||||||
}
|
}
|
||||||
StringView hash_value() const
|
FlyString const& hash_value() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::Hash);
|
VERIFY(m_type == Type::Hash);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Number const& number() const
|
Number const& number() const
|
||||||
|
@ -122,10 +122,10 @@ public:
|
||||||
return m_number_value.integer_value();
|
return m_number_value.integer_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView dimension_unit() const
|
FlyString const& dimension_unit() const
|
||||||
{
|
{
|
||||||
VERIFY(m_type == Type::Dimension);
|
VERIFY(m_type == Type::Dimension);
|
||||||
return m_value.bytes_as_string_view();
|
return m_value;
|
||||||
}
|
}
|
||||||
double dimension_value() const
|
double dimension_value() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue