diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-15 11:57:13 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-16 15:16:27 +0100 |
commit | d775212f19baeec557f8183240af993673f4fd5e (patch) | |
tree | 6a80bb434cb8bc0d0a8002d19ff733aa2ddf2440 /Userland/Libraries/LibWeb/CSS | |
parent | e5d3a9d10b313b53d2c17c14ba380cf81b38452e (diff) | |
download | serenity-d775212f19baeec557f8183240af993673f4fd5e.zip |
LibWeb: Insert commas between serialized CSS selectors
For convenience, we create a Formatter for Selector, so we can use
`StringBuilder.join()`.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Selector.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Selector.h | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.cpp b/Userland/Libraries/LibWeb/CSS/Selector.cpp index 425a7f9cac..34229d574e 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.cpp +++ b/Userland/Libraries/LibWeb/CSS/Selector.cpp @@ -231,8 +231,7 @@ String serialize_a_group_of_selectors(NonnullRefPtrVector<Selector> const& selec { // To serialize a group of selectors serialize each selector in the group of selectors and then serialize a comma-separated list of these serializations. StringBuilder builder; - for (auto& selector : selectors) - builder.append(selector.serialize()); + builder.join(", ", selectors); return builder.to_string(); } diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h index b144ca42de..1db74b89bd 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.h +++ b/Userland/Libraries/LibWeb/CSS/Selector.h @@ -146,3 +146,15 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty String serialize_a_group_of_selectors(NonnullRefPtrVector<Selector> const& selectors); } + +namespace AK { + +template<> +struct Formatter<Web::CSS::Selector> : Formatter<StringView> { + void format(FormatBuilder& builder, Web::CSS::Selector const& selector) + { + Formatter<StringView>::format(builder, selector.serialize()); + } +}; + +} |