diff options
Diffstat (limited to 'Meta/Lagom')
-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(); +} +)~~~"); +} |