mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:38:11 +00:00
LibUnicode: Fallback to per-locale default calendars
When patterns, symbols, etc. for a requested calendar are not found, use the locale's default calendar.
This commit is contained in:
parent
c849cb9d76
commit
b24b9c0a65
1 changed files with 23 additions and 12 deletions
|
@ -2089,21 +2089,32 @@ static CalendarData const* find_calendar_data(StringView locale, StringView cale
|
||||||
if (!locale_value.has_value())
|
if (!locale_value.has_value())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto calendar_keyword = keyword_ca_from_string(calendar);
|
|
||||||
if (!calendar_keyword.has_value())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto calendar_value = keyword_to_calendar(*calendar_keyword);
|
|
||||||
if (!calendar_value.has_value())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
|
auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
|
||||||
size_t calendar_index = to_underlying(*calendar_value);
|
|
||||||
|
|
||||||
auto const& calendar_indices = s_locale_calendars.at(locale_index);
|
auto const& calendar_indices = s_locale_calendars.at(locale_index);
|
||||||
calendar_index = calendar_indices[calendar_index];
|
|
||||||
|
|
||||||
return &s_calendars[calendar_index];
|
auto lookup_calendar = [&](auto calendar_name) -> CalendarData const* {
|
||||||
|
auto calendar_keyword = keyword_ca_from_string(calendar_name);
|
||||||
|
if (!calendar_keyword.has_value())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto calendar_value = keyword_to_calendar(*calendar_keyword);
|
||||||
|
if (!calendar_value.has_value())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
size_t calendar_index = to_underlying(*calendar_value);
|
||||||
|
calendar_index = calendar_indices[calendar_index];
|
||||||
|
|
||||||
|
return &s_calendars[calendar_index];
|
||||||
|
};
|
||||||
|
|
||||||
|
if (auto const* calendar_data = lookup_calendar(calendar))
|
||||||
|
return calendar_data;
|
||||||
|
|
||||||
|
auto default_calendar = get_preferred_keyword_value_for_locale(locale, "ca"sv);
|
||||||
|
if (!default_calendar.has_value())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return lookup_calendar(*default_calendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CalendarFormat> get_calendar_date_format(StringView locale, StringView calendar)
|
Optional<CalendarFormat> get_calendar_date_format(StringView locale, StringView calendar)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue