diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-11-24 13:00:46 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-24 22:57:46 +0100 |
commit | b40388584bc1f72941d8c403c8f1c69b7ff0998b (patch) | |
tree | 301690a3ae7042c7ea27656e5488d2d0a444c4d1 /Userland/Libraries/LibWeb | |
parent | 933a271a789aa0ea6defb7dd26c20e537f4646c9 (diff) | |
download | serenity-b40388584bc1f72941d8c403c8f1c69b7ff0998b.zip |
LibWeb: Make StyleRule to_string() methods output valid CSS
Also removed unused `append_raw()` function.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index cd9af5cf66..50269c73f6 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -11,6 +11,7 @@ #include <LibWeb/CSS/Parser/StyleDeclarationRule.h> #include <LibWeb/CSS/Parser/StyleFunctionRule.h> #include <LibWeb/CSS/Parser/StyleRule.h> +#include <LibWeb/CSS/Serialize.h> namespace Web::CSS { @@ -70,20 +71,7 @@ void append_with_to_string(StringBuilder& builder, SeparatorType& separator, Col first = false; else builder.append(separator); - builder.append(item.to_debug_string()); - } -} - -template<class SeparatorType, class CollectionType> -void append_raw(StringBuilder& builder, SeparatorType& separator, CollectionType& collection) -{ - bool first = true; - for (auto& item : collection) { - if (first) - first = false; - else - builder.append(separator); - builder.append(item); + builder.append(item.to_string()); } } @@ -109,7 +97,7 @@ String StyleRule::to_string() const if (m_type == Type::At) { builder.append("@"); - builder.append(m_name); + serialize_an_identifier(builder, m_name); } append_with_to_string(builder, " ", m_prelude); @@ -127,7 +115,7 @@ String StyleBlockRule::to_string() const StringBuilder builder; builder.append(m_token.bracket_string()); - append_with_to_string(builder, ", ", m_values); + append_with_to_string(builder, " ", m_values); builder.append(m_token.bracket_mirror_string()); return builder.to_string(); @@ -135,21 +123,16 @@ String StyleBlockRule::to_string() const String StyleComponentValueRule::to_string() const { - StringBuilder builder; - switch (m_type) { case StyleComponentValueRule::ComponentType::Token: - builder.append(m_token.to_string()); - break; + return m_token.to_string(); case StyleComponentValueRule::ComponentType::Function: - builder.append(m_function->to_string()); - break; + return m_function->to_string(); case StyleComponentValueRule::ComponentType::Block: - builder.append(m_block->to_string()); - break; + return m_block->to_string(); + default: + VERIFY_NOT_REACHED(); } - - return builder.to_string(); } String StyleComponentValueRule::to_debug_string() const @@ -178,7 +161,7 @@ String StyleDeclarationRule::to_string() const { StringBuilder builder; - builder.append(m_name); + serialize_an_identifier(builder, m_name); builder.append(": "); append_with_to_string(builder, " ", m_values); @@ -192,9 +175,9 @@ String StyleFunctionRule::to_string() const { StringBuilder builder; - builder.append(m_name); + serialize_an_identifier(builder, m_name); builder.append("("); - append_with_to_string(builder, ", ", m_values); + append_with_to_string(builder, " ", m_values); builder.append(")"); return builder.to_string(); |