From 872ad98ebac2a5dae9deb195921291e16d86e1c3 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sun, 17 Apr 2022 15:48:49 +0100 Subject: LibWeb: Generate TransformFunction to/from string functions --- .../LibWeb/GenerateCSSTransformFunctions.cpp | 53 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'Meta') diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp index 31f6c16e80..ce4c25f7cc 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp @@ -53,6 +53,11 @@ ErrorOr generate_header_file(JsonObject& transforms_data, Core::Stream::Fi SourceGenerator generator { builder }; generator.append(R"~~~( +#pragma once + +#include +#include + namespace Web::CSS { )~~~"); @@ -65,6 +70,9 @@ namespace Web::CSS { }); generator.appendln("};"); + generator.appendln("Optional transform_function_from_string(StringView);"); + generator.appendln("StringView to_string(TransformFunction);"); + generator.appendln("\n}"); TRY(file.write(generator.as_string_view().bytes())); @@ -77,15 +85,52 @@ ErrorOr generate_implementation_file(JsonObject& transforms_data, Core::St SourceGenerator generator { builder }; generator.append(R"~~~( +#include +#include + namespace Web::CSS { )~~~"); - transforms_data.for_each_member([&](auto& name, auto& value) { - (void)name; - (void)value; + generator.append(R"~~~( +Optional transform_function_from_string(StringView name) +{ +)~~~"); + transforms_data.for_each_member([&](auto& name, auto&) { + auto member_generator = generator.fork(); + member_generator.set("name", name); + member_generator.set("name:titlecase", title_casify_transform_function(name)); + member_generator.append(R"~~~( + if (name.equals_ignoring_case("@name@"sv)) + return TransformFunction::@name:titlecase@; +)~~~"); + }); + generator.append(R"~~~( + return {}; +} +)~~~"); + + generator.append(R"~~~( +StringView to_string(TransformFunction transform_function) +{ + switch (transform_function) { +)~~~"); + transforms_data.for_each_member([&](auto& name, auto&) { + auto member_generator = generator.fork(); + member_generator.set("name", name); + member_generator.set("name:titlecase", title_casify_transform_function(name)); + member_generator.append(R"~~~( + case TransformFunction::@name:titlecase@: + return "@name@"sv; +)~~~"); }); + generator.append(R"~~~( + default: + VERIFY_NOT_REACHED(); + } +} +)~~~"); - generator.appendln("}"); + generator.appendln("\n}"); TRY(file.write(generator.as_string_view().bytes())); return {}; -- cgit v1.2.3