mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 04:42:57 +00:00
LibWeb: Implement CSS::Token::to_string()
This outputs valid CSS, as opposed to to_debug_string().
This commit is contained in:
parent
3e7e503dee
commit
cf07da082e
|
@ -6,9 +6,71 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/Parser/Token.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
String Token::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
switch (m_type) {
|
||||
case Type::EndOfFile:
|
||||
return "";
|
||||
case Type::Ident:
|
||||
return serialize_an_identifier(ident());
|
||||
case Type::Function:
|
||||
return String::formatted("{}(", serialize_an_identifier(function()));
|
||||
case Type::AtKeyword:
|
||||
return String::formatted("@{}", serialize_an_identifier(at_keyword()));
|
||||
case Type::Hash:
|
||||
return String::formatted("#{}", serialize_an_identifier(hash_value()));
|
||||
case Type::String:
|
||||
return serialize_a_string(string());
|
||||
case Type::BadString:
|
||||
return "";
|
||||
case Type::Url:
|
||||
return serialize_a_url(url());
|
||||
case Type::BadUrl:
|
||||
return "url()";
|
||||
case Type::Delim:
|
||||
return m_value;
|
||||
case Type::Number:
|
||||
return String::number(m_number_value);
|
||||
case Type::Percentage:
|
||||
return String::formatted("{}%", m_number_value);
|
||||
case Type::Dimension:
|
||||
return String::formatted("{}{}", m_number_value, m_unit);
|
||||
case Type::Whitespace:
|
||||
return " ";
|
||||
case Type::CDO:
|
||||
return "<!--";
|
||||
case Type::CDC:
|
||||
return "-->";
|
||||
case Type::Colon:
|
||||
return ":";
|
||||
case Type::Semicolon:
|
||||
return ";";
|
||||
case Type::Comma:
|
||||
return ",";
|
||||
case Type::OpenSquare:
|
||||
return "[";
|
||||
case Type::CloseSquare:
|
||||
return "]";
|
||||
case Type::OpenParen:
|
||||
return "(";
|
||||
case Type::CloseParen:
|
||||
return ")";
|
||||
case Type::OpenCurly:
|
||||
return "{";
|
||||
case Type::CloseCurly:
|
||||
return "}";
|
||||
case Type::Invalid:
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
String Token::to_debug_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -157,6 +157,7 @@ public:
|
|||
String bracket_string() const;
|
||||
String bracket_mirror_string() const;
|
||||
|
||||
String to_string() const;
|
||||
String to_debug_string() const;
|
||||
|
||||
Position const& start_position() const { return m_start_position; }
|
||||
|
|
Loading…
Reference in a new issue