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