mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibWeb: Generate and use to_string(css_enum) functions
The only one that's actually used is for Repeat, but it's easy to generate them so might as well. :^)
This commit is contained in:
parent
ae40e9a66c
commit
c50661067d
2 changed files with 26 additions and 16 deletions
|
@ -77,6 +77,7 @@ enum class ValueID;
|
|||
enum_generator.appendln("};");
|
||||
enum_generator.appendln("Optional<@name:titlecase@> value_id_to_@name:snakecase@(ValueID);");
|
||||
enum_generator.appendln("ValueID to_value_id(@name:titlecase@);");
|
||||
enum_generator.appendln("StringView to_string(@name:titlecase@);");
|
||||
enum_generator.append("\n");
|
||||
});
|
||||
|
||||
|
@ -156,6 +157,31 @@ ValueID to_value_id(@name:titlecase@ @name:snakecase@_value)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
)~~~");
|
||||
|
||||
enum_generator.append(R"~~~(
|
||||
StringView to_string(@name:titlecase@ value)
|
||||
{
|
||||
switch (value) {)~~~");
|
||||
|
||||
for (auto& member : members.values()) {
|
||||
auto member_generator = enum_generator.fork();
|
||||
auto member_name = member.to_string();
|
||||
if (member_name.contains('='))
|
||||
continue;
|
||||
member_generator.set("member:css", member_name);
|
||||
member_generator.set("member:titlecase", title_casify(member_name));
|
||||
|
||||
member_generator.append(R"~~~(
|
||||
case @name:titlecase@::@member:titlecase@:
|
||||
return "@member:css@"sv;)~~~");
|
||||
}
|
||||
|
||||
enum_generator.append(R"~~~(
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
)~~~");
|
||||
});
|
||||
|
||||
|
|
|
@ -72,22 +72,6 @@ inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_val
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
constexpr StringView to_string(Repeat value)
|
||||
{
|
||||
switch (value) {
|
||||
case Repeat::NoRepeat:
|
||||
return "no-repeat"sv;
|
||||
case Repeat::Repeat:
|
||||
return "repeat"sv;
|
||||
case Repeat::Round:
|
||||
return "round"sv;
|
||||
case Repeat::Space:
|
||||
return "space"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
enum class TransformFunction {
|
||||
Matrix,
|
||||
Translate,
|
||||
|
|
Loading…
Add table
Reference in a new issue