浏览代码

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.
Timothy Flynn 3 年之前
父节点
当前提交
63c3437274

+ 0 - 2
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp

@@ -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_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);

+ 2 - 0
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp

@@ -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);
     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);
     locale_data.unique_display_patterns.generate(generator, "DisplayPatternImpl"sv, "s_display_patterns"sv, 30);

+ 0 - 2
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp

@@ -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_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_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);
     locale_data.unique_symbols.generate(generator, s_string_index_type, "s_numeric_symbol_lists"sv);

+ 2 - 2
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h

@@ -533,8 +533,8 @@ Span<StringView const> @name@()
         generator.append(first ? " " : ", ");
         generator.append(first ? " " : ", ");
         first = false;
         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
         else
             generator.append(String::formatted("\"{}\"sv", value));
             generator.append(String::formatted("\"{}\"sv", value));
     }
     }

+ 0 - 1
Userland/Libraries/LibUnicode/DateTimeFormat.cpp

@@ -93,7 +93,6 @@ 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

+ 0 - 2
Userland/Libraries/LibUnicode/DateTimeFormat.h

@@ -189,8 +189,6 @@ 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);

+ 2 - 0
Userland/Libraries/LibUnicode/Locale.cpp

@@ -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<Locale> __attribute__((weak)) locale_from_string(StringView) { return {}; }
 Optional<Language> __attribute__((weak)) language_from_string(StringView) { return {}; }
 Optional<Language> __attribute__((weak)) language_from_string(StringView) { return {}; }
 Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }
 Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }

+ 3 - 0
Userland/Libraries/LibUnicode/Locale.h

@@ -145,6 +145,9 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID&);
 String const& default_locale();
 String const& default_locale();
 bool is_locale_available(StringView 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);
 Style style_from_string(StringView style);
 StringView style_to_string(Style style);
 StringView style_to_string(Style style);
 
 

+ 0 - 1
Userland/Libraries/LibUnicode/NumberFormat.cpp

@@ -16,7 +16,6 @@
 
 
 namespace Unicode {
 namespace Unicode {
 
 
-Span<StringView const> __attribute__((weak)) get_available_number_systems() { return {}; }
 Optional<NumberSystem> __attribute__((weak)) number_system_from_string(StringView) { return {}; }
 Optional<NumberSystem> __attribute__((weak)) number_system_from_string(StringView) { return {}; }
 Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
 Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
 Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }
 Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }

+ 0 - 2
Userland/Libraries/LibUnicode/NumberFormat.h

@@ -66,8 +66,6 @@ enum class NumericSymbol : u8 {
     PlusSign,
     PlusSign,
 };
 };
 
 
-Span<StringView const> get_available_number_systems();
-
 Optional<NumberSystem> number_system_from_string(StringView system);
 Optional<NumberSystem> number_system_from_string(StringView system);
 Optional<StringView> get_default_number_system(StringView locale);
 Optional<StringView> get_default_number_system(StringView locale);