mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
LibWeb: Insert commas between serialized CSS selectors
For convenience, we create a Formatter for Selector, so we can use `StringBuilder.join()`.
This commit is contained in:
parent
e5d3a9d10b
commit
d775212f19
2 changed files with 13 additions and 2 deletions
|
@ -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.
|
// 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;
|
StringBuilder builder;
|
||||||
for (auto& selector : selectors)
|
builder.join(", ", selectors);
|
||||||
builder.append(selector.serialize());
|
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,3 +146,15 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
|
||||||
String serialize_a_group_of_selectors(NonnullRefPtrVector<Selector> const& selectors);
|
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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue