From 6dbdfb6ba1deb222a7324c4f4088cb85c613ab1a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 28 Nov 2021 17:28:14 -0500 Subject: LibUnicode: Add special handling of hour cycle (hc) Unicode keywords For other keywords, allowed values per locale are generated at compile time. But since the CLDR doesn't present hour cycles on a per-locale basis, and hour cycles lookups depend on runtime data, we must handle hour cycle keyword lookups differently than other keywords. --- Userland/Libraries/LibUnicode/Locale.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Userland/Libraries/LibUnicode/Locale.cpp') diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index 4a61523edf..d0dce9e3ed 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #if ENABLE_UNICODE_DATA @@ -806,6 +807,18 @@ Optional get_locale_currency_mapping([[maybe_unused]] StringView loc Vector get_locale_key_mapping([[maybe_unused]] StringView locale, [[maybe_unused]] StringView keyword) { #if ENABLE_UNICODE_DATA + if (keyword == "hc"sv) { + auto hour_cycles = get_regional_hour_cycles(locale); + + Vector 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 = Detail::get_locale_key_mapping(locale, keyword); values.has_value()) return values->split_view(','); #endif -- cgit v1.2.3