浏览代码

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.
Timothy Flynn 3 年之前
父节点
当前提交
16b673eaa9
共有 1 个文件被更改,包括 16 次插入8 次删除
  1. 16 8
      Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp

+ 16 - 8
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 {};
 }