diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-30 16:45:35 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-31 00:32:41 +0000 |
commit | ebd33e580b1b734197f678071545b66883302808 (patch) | |
tree | 3db6d99fe91a55cc29eb945ee85dfe60197dcd8d /Meta | |
parent | 48eecaad645062df450dafbc2d7d98d240ec501e (diff) | |
download | serenity-ebd33e580b1b734197f678071545b66883302808.zip |
LibUnicode: Generate a list of available calendars
Diffstat (limited to 'Meta')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp | 2 | ||||
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index 6afd2df3b8..a6da368542 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -1863,6 +1863,8 @@ struct DayPeriodData { }; )~~~"); + generate_available_values(generator, "get_available_calendars"sv, locale_data.calendars, locale_data.calendar_aliases); + locale_data.unique_formats.generate(generator, "CalendarFormatImpl"sv, "s_calendar_formats"sv, 10); locale_data.unique_symbol_lists.generate(generator, s_string_index_type, "s_symbol_lists"sv); locale_data.unique_calendar_symbols.generate(generator, "CalendarSymbols"sv, "s_calendar_symbols"sv, 10); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h index 669ace5c79..d9c817f6e4 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h @@ -488,3 +488,31 @@ static constexpr Array<Span<@type@ const>, @size@> @name@ { { } }; )~~~"); } + +template<typename T> +void generate_available_values(SourceGenerator& generator, StringView name, Vector<T> const& values, Vector<Alias> const& aliases = {}) +{ + generator.set("name", name); + generator.set("size", String::number(values.size())); + + generator.append(R"~~~( +Span<StringView const> @name@() +{ + static constexpr Array<StringView, @size@> values { {)~~~"); + + bool first = true; + for (auto const& value : values) { + generator.append(first ? " " : ", "); + first = false; + + if (auto it = aliases.find_if([&](auto const& alias) { return alias.name == value; }); it != aliases.end()) + generator.append(String::formatted("\"{}\"sv", it->alias)); + else + generator.append(String::formatted("\"{}\"sv", value)); + } + + generator.append(R"~~~( } }; + return values.span(); +} +)~~~"); +} |