mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibUnicode: Generate a list of available calendars
This commit is contained in:
parent
48eecaad64
commit
ebd33e580b
Notes:
sideshowbarker
2024-07-17 19:57:58 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/ebd33e580b1 Pull-request: https://github.com/SerenityOS/serenity/pull/12223 Reviewed-by: https://github.com/linusg ✅
4 changed files with 33 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style)
|
|||
|
||||
Optional<Calendar> __attribute__((weak)) calendar_from_string(StringView) { return {}; }
|
||||
Optional<HourCycleRegion> __attribute__((weak)) hour_cycle_region_from_string(StringView) { return {}; }
|
||||
Span<StringView const> __attribute__((weak)) get_available_calendars() { return {}; }
|
||||
Vector<HourCycle> __attribute__((weak)) get_regional_hour_cycles(StringView) { return {}; }
|
||||
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
|
|
|
@ -189,6 +189,8 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
|
|||
Optional<Calendar> calendar_from_string(StringView calendar);
|
||||
Optional<HourCycleRegion> hour_cycle_region_from_string(StringView hour_cycle_region);
|
||||
|
||||
Span<StringView const> get_available_calendars();
|
||||
|
||||
Vector<HourCycle> get_regional_hour_cycles(StringView region);
|
||||
Vector<Unicode::HourCycle> get_locale_hour_cycles(StringView locale);
|
||||
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale);
|
||||
|
|
Loading…
Add table
Reference in a new issue