1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 04:37:40 +00:00

LibWeb: Convert CSS Token::to_debug_string() to ::to_string() :^)

Using from_utf8_short_string() for all cases that are <= 3 bytes long.
Which is almost all of the static ones.
This commit is contained in:
Sam Atkins 2023-02-11 16:47:52 +00:00 committed by Linus Groh
parent 2368e6c5f2
commit 476ec563bc
4 changed files with 30 additions and 30 deletions

View file

@ -29,7 +29,7 @@ ComponentValue::~ComponentValue() = default;
DeprecatedString ComponentValue::to_deprecated_string() const DeprecatedString ComponentValue::to_deprecated_string() const
{ {
return m_value.visit( return m_value.visit(
[](Token const& token) { return token.to_deprecated_string(); }, [](Token const& token) { return token.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); },
[](NonnullRefPtr<Block> const& block) { return block->to_deprecated_string(); }, [](NonnullRefPtr<Block> const& block) { return block->to_deprecated_string(); },
[](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); }); [](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); });
} }

View file

@ -562,7 +562,7 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec
} }
// FIXME: Support multiple, comma-separated, language ranges. // FIXME: Support multiple, comma-separated, language ranges.
Vector<DeprecatedFlyString> languages; Vector<DeprecatedFlyString> languages;
languages.append(pseudo_function.values().first().token().to_deprecated_string()); languages.append(pseudo_function.values().first().token().to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string());
return Selector::SimpleSelector { return Selector::SimpleSelector {
.type = Selector::SimpleSelector::Type::PseudoClass, .type = Selector::SimpleSelector::Type::PseudoClass,
.value = Selector::SimpleSelector::PseudoClass { .value = Selector::SimpleSelector::PseudoClass {

View file

@ -11,68 +11,68 @@
namespace Web::CSS::Parser { namespace Web::CSS::Parser {
DeprecatedString Token::to_deprecated_string() const ErrorOr<String> Token::to_string() const
{ {
StringBuilder builder; StringBuilder builder;
switch (m_type) { switch (m_type) {
case Type::EndOfFile: case Type::EndOfFile:
return ""; return String {};
case Type::Ident: case Type::Ident:
return serialize_an_identifier(ident()); return String::from_utf8(serialize_an_identifier(ident()));
case Type::Function: case Type::Function:
return DeprecatedString::formatted("{}(", serialize_an_identifier(function())); return String::formatted("{}(", serialize_an_identifier(function()));
case Type::AtKeyword: case Type::AtKeyword:
return DeprecatedString::formatted("@{}", serialize_an_identifier(at_keyword())); return String::formatted("@{}", serialize_an_identifier(at_keyword()));
case Type::Hash: { case Type::Hash: {
switch (m_hash_type) { switch (m_hash_type) {
case HashType::Id: case HashType::Id:
return DeprecatedString::formatted("#{}", serialize_an_identifier(hash_value())); return String::formatted("#{}", serialize_an_identifier(hash_value()));
case HashType::Unrestricted: case HashType::Unrestricted:
return DeprecatedString::formatted("#{}", hash_value()); return String::formatted("#{}", hash_value());
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
case Type::String: case Type::String:
return serialize_a_string(string()); return String::from_utf8(serialize_a_string(string()));
case Type::BadString: case Type::BadString:
return ""; return String {};
case Type::Url: case Type::Url:
return serialize_a_url(url()); return String::from_utf8(serialize_a_url(url()));
case Type::BadUrl: case Type::BadUrl:
return "url()"; return String::from_utf8("url()"sv);
case Type::Delim: case Type::Delim:
return DeprecatedString(m_value.bytes_as_string_view()); return String { m_value };
case Type::Number: case Type::Number:
return DeprecatedString::number(m_number_value.value()); return String::number(m_number_value.value());
case Type::Percentage: case Type::Percentage:
return DeprecatedString::formatted("{}%", m_number_value.value()); return String::formatted("{}%", m_number_value.value());
case Type::Dimension: case Type::Dimension:
return DeprecatedString::formatted("{}{}", m_number_value.value(), dimension_unit()); return String::formatted("{}{}", m_number_value.value(), dimension_unit());
case Type::Whitespace: case Type::Whitespace:
return " "; return String::from_utf8_short_string(" "sv);
case Type::CDO: case Type::CDO:
return "<!--"; return String::from_utf8("<!--"sv);
case Type::CDC: case Type::CDC:
return "-->"; return String::from_utf8_short_string("-->"sv);
case Type::Colon: case Type::Colon:
return ":"; return String::from_utf8_short_string(":"sv);
case Type::Semicolon: case Type::Semicolon:
return ";"; return String::from_utf8_short_string(";"sv);
case Type::Comma: case Type::Comma:
return ","; return String::from_utf8_short_string(","sv);
case Type::OpenSquare: case Type::OpenSquare:
return "["; return String::from_utf8_short_string("["sv);
case Type::CloseSquare: case Type::CloseSquare:
return "]"; return String::from_utf8_short_string("]"sv);
case Type::OpenParen: case Type::OpenParen:
return "("; return String::from_utf8_short_string("("sv);
case Type::CloseParen: case Type::CloseParen:
return ")"; return String::from_utf8_short_string(")"sv);
case Type::OpenCurly: case Type::OpenCurly:
return "{"; return String::from_utf8_short_string("{"sv);
case Type::CloseCurly: case Type::CloseCurly:
return "}"; return String::from_utf8_short_string("}"sv);
case Type::Invalid: case Type::Invalid:
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View file

@ -145,7 +145,7 @@ public:
StringView bracket_string() const; StringView bracket_string() const;
StringView bracket_mirror_string() const; StringView bracket_mirror_string() const;
DeprecatedString to_deprecated_string() const; ErrorOr<String> to_string() const;
ErrorOr<String> to_debug_string() const; ErrorOr<String> to_debug_string() const;
Position const& start_position() const { return m_start_position; } Position const& start_position() const { return m_start_position; }