1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +00:00

LibLocale+LibJS: Port locale parsing and processing to String

In order to prevent this commit from having to refactor almost all of
Intl, the goal here is to update the internal parsing/canonicalization
of locales within LibLocale only. Call sites which are already equiped
to handle String and OOM errors do so, however.
This commit is contained in:
Timothy Flynn 2023-01-19 10:53:20 -05:00 committed by Linus Groh
parent 618714e29a
commit ca62aeb6bd
11 changed files with 371 additions and 299 deletions

View file

@ -36,17 +36,17 @@ Locale::Locale(::Locale::LocaleID const& locale_id, Object& prototype)
for (auto const& keyword : extension.get<::Locale::LocaleExtension>().keywords) {
if (keyword.key == "ca"sv) {
set_calendar(keyword.value);
set_calendar(keyword.value.to_deprecated_string());
} else if (keyword.key == "co"sv) {
set_collation(keyword.value);
set_collation(keyword.value.to_deprecated_string());
} else if (keyword.key == "hc"sv) {
set_hour_cycle(keyword.value);
set_hour_cycle(keyword.value.to_deprecated_string());
} else if (keyword.key == "kf"sv) {
set_case_first(keyword.value);
set_case_first(keyword.value.to_deprecated_string());
} else if (keyword.key == "kn"sv) {
set_numeric(keyword.value.is_empty());
} else if (keyword.key == "nu"sv) {
set_numbering_system(keyword.value);
set_numbering_system(keyword.value.to_deprecated_string());
}
}
@ -81,7 +81,7 @@ Array* calendars_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical calendar identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "ca"sv);
@ -100,7 +100,7 @@ Array* collations_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical collation identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, ordered as if an Array of the same values had been sorted, using %Array.prototype.sort% using undefined as comparefn, of those in common use for string comparison in locale. The values "standard" and "search" must be excluded from list.
auto list = ::Locale::get_keywords_for_locale(locale, "co"sv);
@ -119,7 +119,7 @@ Array* hour_cycles_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format ("h11", "h12") or the 24-hour format ("h23", "h24"), sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "hc"sv);
@ -138,7 +138,7 @@ Array* numbering_systems_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 4. Let list be a List of 1 or more unique canonical numbering system identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for formatting numeric values in locale.
auto list = ::Locale::get_keywords_for_locale(locale, "nu"sv);
@ -174,7 +174,7 @@ StringView character_direction_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 3. If the default general ordering of characters (characterOrder) within a line in locale is right-to-left, return "rtl".
// NOTE: LibUnicode handles both LTR and RTL character orders in this call, not just RTL. We then fallback to LTR
@ -235,7 +235,7 @@ WeekInfo week_info_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value());
VERIFY(::Locale::parse_unicode_locale_id(locale).release_value_but_fixme_should_propagate_errors().has_value());
// 3. Return a record whose fields are defined by Table 1, with values based on locale.
WeekInfo week_info {};