mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibUnicode: Generate a list of available calendars
This commit is contained in:
parent
48eecaad64
commit
ebd33e580b
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_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_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);
|
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<Calendar> __attribute__((weak)) calendar_from_string(StringView) { return {}; }
|
||||||
Optional<HourCycleRegion> __attribute__((weak)) hour_cycle_region_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 {}; }
|
Vector<HourCycle> __attribute__((weak)) get_regional_hour_cycles(StringView) { return {}; }
|
||||||
|
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
// 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<Calendar> calendar_from_string(StringView calendar);
|
||||||
Optional<HourCycleRegion> hour_cycle_region_from_string(StringView hour_cycle_region);
|
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<HourCycle> get_regional_hour_cycles(StringView region);
|
||||||
Vector<Unicode::HourCycle> get_locale_hour_cycles(StringView locale);
|
Vector<Unicode::HourCycle> get_locale_hour_cycles(StringView locale);
|
||||||
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale);
|
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue