mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibUnicode: Use BCP 47 data to generate available calendars and numbers
BCP 47 will be the single source of truth for known calendar and number system keywords, and their aliases (e.g. "gregory" is an alias for "gregorian"). Move the generation of available keywords to where we parse the BCP 47 data, so that hard-coded aliases may be removed from other generators.
This commit is contained in:
parent
89ead8c00a
commit
63c3437274
Notes:
sideshowbarker
2024-07-17 18:43:23 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/63c3437274 Pull-request: https://github.com/SerenityOS/serenity/pull/12558
10 changed files with 9 additions and 12 deletions
|
@ -1855,8 +1855,6 @@ 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);
|
||||
|
|
|
@ -1054,6 +1054,8 @@ struct Patterns {
|
|||
};
|
||||
)~~~");
|
||||
|
||||
generate_available_values(generator, "get_available_calendars"sv, locale_data.keywords.find("ca"sv)->value, locale_data.keyword_aliases.find("ca"sv)->value);
|
||||
generate_available_values(generator, "get_available_number_systems"sv, locale_data.keywords.find("nu"sv)->value, locale_data.keyword_aliases.find("nu"sv)->value);
|
||||
generate_available_values(generator, "get_available_currencies"sv, locale_data.currencies);
|
||||
|
||||
locale_data.unique_display_patterns.generate(generator, "DisplayPatternImpl"sv, "s_display_patterns"sv, 30);
|
||||
|
|
|
@ -865,8 +865,6 @@ struct Unit {
|
|||
};
|
||||
)~~~");
|
||||
|
||||
generate_available_values(generator, "get_available_number_systems"sv, locale_data.number_systems);
|
||||
|
||||
locale_data.unique_formats.generate(generator, "NumberFormatImpl"sv, "s_number_formats"sv, 10);
|
||||
locale_data.unique_format_lists.generate(generator, s_number_format_index_type, "s_number_format_lists"sv);
|
||||
locale_data.unique_symbols.generate(generator, s_string_index_type, "s_numeric_symbol_lists"sv);
|
||||
|
|
|
@ -533,8 +533,8 @@ Span<StringView const> @name@()
|
|||
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));
|
||||
if (auto it = aliases.find_if([&](auto const& alias) { return alias.alias == value; }); it != aliases.end())
|
||||
generator.append(String::formatted("\"{}\"sv", it->name));
|
||||
else
|
||||
generator.append(String::formatted("\"{}\"sv", value));
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ 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,8 +189,6 @@ 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);
|
||||
|
|
|
@ -766,6 +766,8 @@ StringView style_to_string(Style style)
|
|||
}
|
||||
}
|
||||
|
||||
Span<StringView const> __attribute__((weak)) get_available_calendars() { return {}; }
|
||||
Span<StringView const> __attribute__((weak)) get_available_number_systems() { return {}; }
|
||||
Optional<Locale> __attribute__((weak)) locale_from_string(StringView) { return {}; }
|
||||
Optional<Language> __attribute__((weak)) language_from_string(StringView) { return {}; }
|
||||
Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }
|
||||
|
|
|
@ -145,6 +145,9 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID&);
|
|||
String const& default_locale();
|
||||
bool is_locale_available(StringView locale);
|
||||
|
||||
Span<StringView const> get_available_calendars();
|
||||
Span<StringView const> get_available_number_systems();
|
||||
|
||||
Style style_from_string(StringView style);
|
||||
StringView style_to_string(Style style);
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
namespace Unicode {
|
||||
|
||||
Span<StringView const> __attribute__((weak)) get_available_number_systems() { return {}; }
|
||||
Optional<NumberSystem> __attribute__((weak)) number_system_from_string(StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
|
||||
Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }
|
||||
|
|
|
@ -66,8 +66,6 @@ enum class NumericSymbol : u8 {
|
|||
PlusSign,
|
||||
};
|
||||
|
||||
Span<StringView const> get_available_number_systems();
|
||||
|
||||
Optional<NumberSystem> number_system_from_string(StringView system);
|
||||
Optional<StringView> get_default_number_system(StringView locale);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue