diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp index 555ef475c3..0457d44d18 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp @@ -131,7 +131,7 @@ struct AK::Formatter : Formatter { ErrorOr format(FormatBuilder& builder, ListPatterns const& patterns) { return Formatter::format(builder, - "{{ ListPatternType::{}, ListPatternStyle::{}, {}, {}, {}, {} }}", + "{{ ListPatternType::{}, Style::{}, {}, {}, {}, {} }}", format_identifier({}, patterns.type), format_identifier({}, patterns.style), patterns.start, @@ -217,7 +217,6 @@ struct UnicodeLocaleData { }; Vector keywords { "ca"sv, "nu"sv }; // FIXME: These should be parsed from BCP47. https://unicode-org.atlassian.net/browse/CLDR-15158 Vector list_pattern_types; - Vector list_pattern_styles; HashMap language_aliases; HashMap territory_aliases; HashMap script_aliases; @@ -507,8 +506,6 @@ static ErrorOr parse_locale_list_patterns(String misc_path, UnicodeLocaleD if (!locale_data.list_pattern_types.contains_slow(type)) locale_data.list_pattern_types.append(type); - if (!locale_data.list_pattern_styles.contains_slow(style)) - locale_data.list_pattern_styles.append(style); ListPatterns list_pattern { type, style, start, middle, end, pair }; list_patterns.append(locale_data.unique_list_patterns.ensure(move(list_pattern))); @@ -953,7 +950,6 @@ namespace Unicode { generate_enum(generator, format_identifier, "Key"sv, {}, locale_data.keywords); generate_enum(generator, format_identifier, "Variant"sv, {}, locale_data.variants); generate_enum(generator, format_identifier, "ListPatternType"sv, {}, locale_data.list_pattern_types); - generate_enum(generator, format_identifier, "ListPatternStyle"sv, {}, locale_data.list_pattern_styles); generator.append(R"~~~( } @@ -1003,7 +999,7 @@ struct DisplayPatternImpl { struct Patterns { ListPatternType type; - ListPatternStyle style; + Style style; @string_index_type@ start { 0 }; @string_index_type@ middle { 0 }; @string_index_type@ end { 0 }; @@ -1356,7 +1352,6 @@ Optional get_locale_@enum_snake@_mapping(StringView locale, StringVi append_alias_search("subdivision"sv, locale_data.subdivision_aliases); append_from_string("ListPatternType"sv, "list_pattern_type"sv, locale_data.list_pattern_types); - append_from_string("ListPatternStyle"sv, "list_pattern_style"sv, locale_data.list_pattern_styles); generator.append(R"~~~( Optional get_locale_display_patterns(StringView locale) @@ -1372,7 +1367,7 @@ Optional get_locale_display_patterns(StringView locale) return display_patterns.to_display_pattern(); } -Optional get_locale_list_patterns(StringView locale, StringView list_pattern_type, StringView list_pattern_style) +Optional get_locale_list_patterns(StringView locale, StringView list_pattern_type, Style list_pattern_style) { auto locale_value = locale_from_string(locale); if (!locale_value.has_value()) @@ -1382,10 +1377,6 @@ Optional get_locale_list_patterns(StringView locale, StringView li if (!type_value.has_value()) return {}; - auto style_value = list_pattern_style_from_string(list_pattern_style); - if (!style_value.has_value()) - return {}; - auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None. auto list_patterns_list_index = s_locale_list_patterns.at(locale_index); @@ -1394,7 +1385,7 @@ Optional get_locale_list_patterns(StringView locale, StringView li for (auto list_patterns_index : locale_list_patterns) { auto const& list_patterns = s_list_patterns.at(list_patterns_index); - if ((list_patterns.type == type_value) && (list_patterns.style == style_value)) { + if ((list_patterns.type == type_value) && (list_patterns.style == list_pattern_style)) { auto const& start = s_string_list[list_patterns.start]; auto const& middle = s_string_list[list_patterns.middle]; auto const& end = s_string_list[list_patterns.end]; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index b43069afa3..c3e9a04ada 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -9,7 +9,6 @@ #include #include #include -#include namespace JS::Intl { @@ -46,33 +45,6 @@ StringView ListFormat::type_string() const } } -void ListFormat::set_style(StringView style) -{ - if (style == "narrow"sv) { - m_style = Style::Narrow; - } else if (style == "short"sv) { - m_style = Style::Short; - } else if (style == "long"sv) { - m_style = Style::Long; - } else { - VERIFY_NOT_REACHED(); - } -} - -StringView ListFormat::style_string() const -{ - switch (m_style) { - case Style::Narrow: - return "narrow"sv; - case Style::Short: - return "short"sv; - case Style::Long: - return "long"sv; - default: - VERIFY_NOT_REACHED(); - } -} - // 13.1.1 DeconstructPattern ( pattern, placeables ), https://tc39.es/ecma402/#sec-deconstructpattern Vector deconstruct_pattern(StringView pattern, Placeables placeables) { @@ -123,7 +95,7 @@ Vector deconstruct_pattern(StringView pattern, Placeables plac // 13.1.2 CreatePartsFromList ( listFormat, list ), https://tc39.es/ecma402/#sec-createpartsfromlist Vector create_parts_from_list(ListFormat const& list_format, Vector const& list) { - auto list_patterns = Unicode::get_locale_list_patterns(list_format.locale(), list_format.type_string(), list_format.style_string()); + auto list_patterns = Unicode::get_locale_list_patterns(list_format.locale(), list_format.type_string(), list_format.style()); if (!list_patterns.has_value()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h index 0eeb62957d..657db6272b 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace JS::Intl { @@ -27,13 +28,6 @@ public: Unit, }; - enum class Style { - Invalid, - Narrow, - Short, - Long, - }; - ListFormat(Object& prototype); virtual ~ListFormat() override = default; @@ -44,14 +38,14 @@ public: void set_type(StringView type); StringView type_string() const; - Style style() const { return m_style; } - void set_style(StringView style); - StringView style_string() const; + Unicode::Style style() const { return m_style; } + void set_style(StringView style) { m_style = Unicode::style_from_string(style); } + StringView style_string() const { return Unicode::style_to_string(m_style); } private: - String m_locale; // [[Locale]] - Type m_type { Type::Invalid }; // [[Type]] - Style m_style { Style::Invalid }; // [[Style]] + String m_locale; // [[Locale]] + Type m_type { Type::Invalid }; // [[Type]] + Unicode::Style m_style { Unicode::Style::Long }; // [[Style]] }; using Placeables = HashMap>>; diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index b34ef5b83b..fc2e5d907e 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -775,7 +775,6 @@ Optional __attribute__((weak)) calendar_name_from_string(StringVie Optional __attribute__((weak)) date_field_from_string(StringView) { return {}; } Optional __attribute__((weak)) key_from_string(StringView) { return {}; } Optional __attribute__((weak)) list_pattern_type_from_string(StringView) { return {}; } -Optional __attribute__((weak)) list_pattern_style_from_string(StringView) { return {}; } Optional __attribute__((weak)) get_locale_display_patterns(StringView) { return {}; } Optional __attribute__((weak)) get_locale_language_mapping(StringView, StringView) { return {}; } Optional __attribute__((weak)) get_locale_territory_mapping(StringView, StringView) { return {}; } @@ -844,7 +843,7 @@ Vector get_locale_key_mapping_list(StringView locale, StringView key return {}; } -Optional __attribute__((weak)) get_locale_list_patterns(StringView, StringView, StringView) { return {}; } +Optional __attribute__((weak)) get_locale_list_patterns(StringView, StringView, Style) { return {}; } Optional __attribute__((weak)) resolve_language_alias(StringView) { return {}; } Optional __attribute__((weak)) resolve_territory_alias(StringView) { return {}; } Optional __attribute__((weak)) resolve_script_tag_alias(StringView) { return {}; } diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index 9fd15c63d6..30cf6cb789 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -157,7 +157,6 @@ Optional calendar_name_from_string(StringView calendar); Optional date_field_from_string(StringView calendar); Optional key_from_string(StringView key); Optional list_pattern_type_from_string(StringView list_pattern_type); -Optional list_pattern_style_from_string(StringView list_pattern_style); Optional get_locale_display_patterns(StringView locale); Optional format_locale_for_display(StringView locale, LocaleID locale_id); @@ -176,7 +175,7 @@ Optional get_locale_narrow_date_field_mapping(StringView locale, Str Optional get_locale_key_mapping(StringView locale, StringView keyword); Vector get_locale_key_mapping_list(StringView locale, StringView keyword); -Optional get_locale_list_patterns(StringView locale, StringView type, StringView style); +Optional get_locale_list_patterns(StringView locale, StringView type, Style style); Optional resolve_language_alias(StringView language); Optional resolve_territory_alias(StringView territory);