diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-07-21 12:10:01 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-21 20:36:03 +0100 |
commit | 16b673eaa9d39febd61b7b19b75a574236dc8e6d (patch) | |
tree | 984f9452bd94735ffe32d67be1c3063689469fa9 /Meta | |
parent | 0f26ab89aeaf5975640aa7e676a8194ab73910fb (diff) | |
download | serenity-16b673eaa9d39febd61b7b19b75a574236dc8e6d.zip |
LibUnicode: Check whether a calendar symbol for a locale actually exists
In the generated unique string list, index 0 is the empty string, and is
used to indicate a value doesn't exist in the CLDR. Check for this
before returning an empty calendar symbol.
For example, an upcoming commit will add the fixed day period "noon",
which not all locales support.
Diffstat (limited to 'Meta')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index ab6f3847b3..9ef8e893dd 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -2240,8 +2240,10 @@ Optional<StringView> get_calendar_era_symbol(StringView locale, StringView calen { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Era, style); - if (auto value_index = to_underlying(value); value_index < symbols.size()) - return s_string_list[symbols.at(value_index)]; + if (auto value_index = to_underlying(value); value_index < symbols.size()) { + if (auto symbol_index = symbols.at(value_index); symbol_index != 0) + return s_string_list[symbol_index]; + } return {}; } @@ -2250,8 +2252,10 @@ Optional<StringView> get_calendar_month_symbol(StringView locale, StringView cal { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Month, style); - if (auto value_index = to_underlying(value); value_index < symbols.size()) - return s_string_list[symbols.at(value_index)]; + if (auto value_index = to_underlying(value); value_index < symbols.size()) { + if (auto symbol_index = symbols.at(value_index); symbol_index != 0) + return s_string_list[symbol_index]; + } return {}; } @@ -2260,8 +2264,10 @@ Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView c { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Weekday, style); - if (auto value_index = to_underlying(value); value_index < symbols.size()) - return s_string_list[symbols.at(value_index)]; + if (auto value_index = to_underlying(value); value_index < symbols.size()) { + if (auto symbol_index = symbols.at(value_index); symbol_index != 0) + return s_string_list[symbol_index]; + } return {}; } @@ -2270,8 +2276,10 @@ Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringVie { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::DayPeriod, style); - if (auto value_index = to_underlying(value); value_index < symbols.size()) - return s_string_list[symbols.at(value_index)]; + if (auto value_index = to_underlying(value); value_index < symbols.size()) { + if (auto symbol_index = symbols.at(value_index); symbol_index != 0) + return s_string_list[symbol_index]; + } return {}; } |