mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +00:00
AK: Eradicate the uses of out().
This commit is contained in:
parent
61e73b1a7b
commit
88bca152c9
Notes:
sideshowbarker
2024-07-19 01:46:44 +09:00
Author: https://github.com/asynts
Commit: 88bca152c9
Pull-request: https://github.com/SerenityOS/serenity/pull/3828
7 changed files with 475 additions and 259 deletions
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/SourceGenerator.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <ctype.h>
|
||||
|
@ -48,7 +49,7 @@ static String title_casify(const String& dashy_name)
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s <path/to/CSS/Properties.json>\n", argv[0]);
|
||||
warnln("usage: {} <path/to/CSS/Properties.json>", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
auto file = Core::File::construct(argv[1]);
|
||||
|
@ -59,34 +60,59 @@ int main(int argc, char** argv)
|
|||
ASSERT(json.has_value());
|
||||
ASSERT(json.value().is_object());
|
||||
|
||||
out() << "#include <AK/Assertions.h>";
|
||||
out() << "#include <LibWeb/CSS/PropertyID.h>";
|
||||
out() << "namespace Web::CSS {";
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
|
||||
out() << "PropertyID property_id_from_string(const StringView& string) {";
|
||||
generator.append(R"~~~(
|
||||
#include <AK/Assertions.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
PropertyID property_id_from_string(const StringView& string)
|
||||
{
|
||||
)~~~");
|
||||
|
||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
||||
ASSERT(value.is_object());
|
||||
out() << " if (string.equals_ignoring_case(\"" << name << "\"))";
|
||||
out() << " return PropertyID::" << title_casify(name) << ";";
|
||||
|
||||
auto member_generator = generator.fork();
|
||||
member_generator.set("name", name);
|
||||
member_generator.set("name:titlecase", title_casify(name));
|
||||
member_generator.append(R"~~~(
|
||||
if (string.equals_ignoring_case("@name@"))
|
||||
return PropertyID::@name:titlecase@;
|
||||
)~~~");
|
||||
});
|
||||
|
||||
out() << " return PropertyID::Invalid;";
|
||||
|
||||
out() << "}";
|
||||
|
||||
out() << "const char* string_from_property_id(PropertyID property_id) {";
|
||||
out() << " switch (property_id) {";
|
||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
||||
ASSERT(value.is_object());
|
||||
out() << " case PropertyID::" << title_casify(name) << ":";
|
||||
out() << " return \"" << name << "\";";
|
||||
});
|
||||
out() << " default:";
|
||||
out() << " return \"(invalid CSS::PropertyID)\";";
|
||||
out() << " }";
|
||||
out() << "}";
|
||||
out() << "}";
|
||||
|
||||
return 0;
|
||||
generator.append(R"~~~(
|
||||
return PropertyID::Invalid;
|
||||
}
|
||||
|
||||
const char* string_from_property_id(PropertyID property_id) {
|
||||
switch (property_id) {
|
||||
)~~~");
|
||||
|
||||
json.value().as_object().for_each_member([&](auto& name, auto& value) {
|
||||
ASSERT(value.is_object());
|
||||
|
||||
auto member_generator = generator.fork();
|
||||
member_generator.set("name", name);
|
||||
member_generator.set("name:titlecase", title_casify(name));
|
||||
member_generator.append(R"~~~(
|
||||
case PropertyID::@name:titlecase@:
|
||||
return "@name@";
|
||||
)~~~");
|
||||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
default:
|
||||
return "(invalid CSS::PropertyID)";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Web::CSS
|
||||
)~~~");
|
||||
|
||||
outln("{}", generator.as_string_view());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue