Просмотр исходного кода

LibJS+LibUnicode: Rename method to select a NumberFormat plurality

Instead of currency pattern lookups within select_currency_unit_pattern,
rename the method to select_pattern_with_plurality and accept any list
of patterns. This method will be needed for units.
Timothy Flynn 3 лет назад
Родитель
Сommit
6d34a0b4e8

+ 3 - 1
Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp

@@ -1370,7 +1370,9 @@ Optional<Variant<StringView, String>> get_number_format_pattern(NumberFormat& nu
 
         // Handling of other [[CurrencyDisplay]] options will occur after [[SignDisplay]].
         if (number_format.currency_display() == NumberFormat::CurrencyDisplay::Name) {
-            auto maybe_patterns = Unicode::select_currency_unit_pattern(number_format.data_locale(), number_format.numbering_system(), number);
+            auto formats = Unicode::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), Unicode::CompactNumberFormatType::CurrencyUnit);
+
+            auto maybe_patterns = Unicode::select_pattern_with_plurality(formats, number);
             if (maybe_patterns.has_value()) {
                 patterns = maybe_patterns.release_value();
                 break;

+ 1 - 3
Userland/Libraries/LibUnicode/Locale.cpp

@@ -975,13 +975,11 @@ String resolve_most_likely_territory([[maybe_unused]] LanguageID const& language
     return aliases[0].to_string();
 }
 
-Optional<NumberFormat> select_currency_unit_pattern(StringView locale, StringView system, double number)
+Optional<NumberFormat> select_pattern_with_plurality(Vector<NumberFormat> const& formats, double number)
 {
     // FIXME: This is a rather naive and locale-unaware implementation Unicode's TR-35 pluralization
     //        rules: https://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
     //        Once those rules are implemented for LibJS, we better use them instead.
-    auto formats = get_compact_number_system_formats(locale, system, CompactNumberFormatType::CurrencyUnit);
-
     auto find_plurality = [&](auto plurality) -> Optional<NumberFormat> {
         if (auto it = formats.find_if([&](auto& patterns) { return patterns.plurality == plurality; }); it != formats.end())
             return *it;

+ 1 - 1
Userland/Libraries/LibUnicode/Locale.h

@@ -203,7 +203,7 @@ Optional<LanguageID> add_likely_subtags(LanguageID const& language_id);
 Optional<LanguageID> remove_likely_subtags(LanguageID const& language_id);
 String resolve_most_likely_territory(LanguageID const& language_id, StringView territory_alias);
 
-Optional<NumberFormat> select_currency_unit_pattern(StringView locale, StringView system, double number);
+Optional<NumberFormat> select_pattern_with_plurality(Vector<NumberFormat> const& formats, double number);
 Optional<String> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
 
 }