Higher level implementation of attributes to json formatting

This commit is contained in:
Maxime Coste 2017-01-04 23:19:18 +00:00
parent 60d0813704
commit d991420140

View File

@ -73,7 +73,7 @@ String to_json(Color color)
String to_json(Attribute attributes)
{
struct { Attribute attr; StringView name; }
struct Attr { Attribute attr; StringView name; }
attrs[] {
{ Attribute::Exclusive, "exclusive" },
{ Attribute::Underline, "underline" },
@ -84,17 +84,10 @@ String to_json(Attribute attributes)
{ Attribute::Italic, "italic" },
};
String res;
for (auto& attr : attrs)
{
if (not (attributes & attr.attr))
continue;
if (not res.empty())
res += ", ";
res += to_json(attr.name);
}
return "[" + res + "]";
return "[" + join(attrs |
filter([=](const Attr& a) { return attributes & a.attr; }) |
transform([](const Attr& a) { return to_json(a.name); }),
',', false) + "]";
}
String to_json(Face face)