mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
LibJS+LibUnicode: Parse Unicode keywords from the BCP 47 CLDR package
We have a fair amount of hard-coded keywords / aliases that can now be replaced with real data from BCP 47. As a result, the also changes the awkward way we were previously generating keys. Before, we were more or less generating keywords as a CSV list of keys, e.g. for the "nu" key, we'd generate "latn,arab,grek" (ordered by locale preference). Then at runtime, we'd split on the comma. We now just generate spans of keywords directly.
This commit is contained in:
parent
d0fc61e79b
commit
89ead8c00a
6 changed files with 236 additions and 121 deletions
|
@ -771,10 +771,14 @@ Optional<Language> __attribute__((weak)) language_from_string(StringView) { retu
|
|||
Optional<Territory> __attribute__((weak)) territory_from_string(StringView) { return {}; }
|
||||
Optional<ScriptTag> __attribute__((weak)) script_tag_from_string(StringView) { return {}; }
|
||||
Optional<Currency> __attribute__((weak)) currency_from_string(StringView) { return {}; }
|
||||
Optional<CalendarName> __attribute__((weak)) calendar_name_from_string(StringView) { return {}; }
|
||||
Optional<DateField> __attribute__((weak)) date_field_from_string(StringView) { return {}; }
|
||||
Optional<Key> __attribute__((weak)) key_from_string(StringView) { return {}; }
|
||||
Optional<ListPatternType> __attribute__((weak)) list_pattern_type_from_string(StringView) { return {}; }
|
||||
Optional<Key> __attribute__((weak)) key_from_string(StringView) { return {}; }
|
||||
Optional<KeywordCalendar> __attribute__((weak)) keyword_ca_from_string(StringView) { return {}; }
|
||||
Optional<KeywordColCaseFirst> __attribute__((weak)) keyword_kf_from_string(StringView) { return {}; }
|
||||
Optional<KeywordColNumeric> __attribute__((weak)) keyword_kn_from_string(StringView) { return {}; }
|
||||
Optional<KeywordNumbers> __attribute__((weak)) keyword_nu_from_string(StringView) { return {}; }
|
||||
Vector<StringView> __attribute__((weak)) get_keywords_for_locale(StringView, StringView) { return {}; }
|
||||
Optional<DisplayPattern> __attribute__((weak)) get_locale_display_patterns(StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_language_mapping(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_territory_mapping(StringView, StringView) { return {}; }
|
||||
|
@ -787,7 +791,6 @@ Optional<StringView> __attribute__((weak)) get_locale_calendar_mapping(StringVie
|
|||
Optional<StringView> __attribute__((weak)) get_locale_long_date_field_mapping(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_short_date_field_mapping(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_narrow_date_field_mapping(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_key_mapping(StringView, StringView) { return {}; }
|
||||
|
||||
// https://www.unicode.org/reports/tr35/tr35-39/tr35-general.html#Display_Name_Elements
|
||||
Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id)
|
||||
|
@ -823,26 +826,6 @@ Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id
|
|||
return patterns->locale_pattern.replace("{0}"sv, primary_tag).replace("{1}"sv, *secondary_tag);
|
||||
}
|
||||
|
||||
Vector<StringView> get_locale_key_mapping_list(StringView locale, StringView keyword)
|
||||
{
|
||||
if (keyword == "hc"sv) {
|
||||
auto hour_cycles = get_locale_hour_cycles(locale);
|
||||
|
||||
Vector<StringView> values;
|
||||
values.ensure_capacity(hour_cycles.size());
|
||||
|
||||
for (auto hour_cycle : hour_cycles)
|
||||
values.unchecked_append(hour_cycle_to_string(hour_cycle));
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
if (auto values = get_locale_key_mapping(locale, keyword); values.has_value())
|
||||
return values->split_view(',');
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<ListPatterns> __attribute__((weak)) get_locale_list_patterns(StringView, StringView, Style) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) resolve_language_alias(StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) resolve_territory_alias(StringView) { return {}; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue