mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 20:37:35 +00:00
LibJS+LibLocale: Propagate errors from find_regional_values_for_locale
This had quite the footprint.
This commit is contained in:
parent
b2097f4059
commit
5e29e04122
16 changed files with 184 additions and 183 deletions
|
@ -94,8 +94,8 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style)
|
|||
Optional<HourCycleRegion> __attribute__((weak)) hour_cycle_region_from_string(StringView) { return {}; }
|
||||
Vector<HourCycle> __attribute__((weak)) get_regional_hour_cycles(StringView) { return {}; }
|
||||
|
||||
template<typename GetRegionalValues>
|
||||
static auto find_regional_values_for_locale(StringView locale, GetRegionalValues&& get_regional_values)
|
||||
template<typename T, typename GetRegionalValues>
|
||||
static ErrorOr<T> find_regional_values_for_locale(StringView locale, GetRegionalValues&& get_regional_values)
|
||||
{
|
||||
auto has_value = [](auto const& container) {
|
||||
if constexpr (requires { container.has_value(); })
|
||||
|
@ -109,12 +109,12 @@ static auto find_regional_values_for_locale(StringView locale, GetRegionalValues
|
|||
|
||||
auto return_default_values = [&]() { return get_regional_values("001"sv); };
|
||||
|
||||
auto language = parse_unicode_language_id(locale).release_value_but_fixme_should_propagate_errors();
|
||||
auto language = TRY(parse_unicode_language_id(locale));
|
||||
if (!language.has_value())
|
||||
return return_default_values();
|
||||
|
||||
if (!language->region.has_value())
|
||||
language = add_likely_subtags(*language).release_value_but_fixme_should_propagate_errors();
|
||||
language = TRY(add_likely_subtags(*language));
|
||||
if (!language.has_value() || !language->region.has_value())
|
||||
return return_default_values();
|
||||
|
||||
|
@ -125,48 +125,48 @@ static auto find_regional_values_for_locale(StringView locale, GetRegionalValues
|
|||
}
|
||||
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
Vector<HourCycle> get_locale_hour_cycles(StringView locale)
|
||||
ErrorOr<Vector<HourCycle>> get_locale_hour_cycles(StringView locale)
|
||||
{
|
||||
return find_regional_values_for_locale(locale, get_regional_hour_cycles);
|
||||
return find_regional_values_for_locale<Vector<HourCycle>>(locale, get_regional_hour_cycles);
|
||||
}
|
||||
|
||||
Optional<HourCycle> get_default_regional_hour_cycle(StringView locale)
|
||||
ErrorOr<Optional<HourCycle>> get_default_regional_hour_cycle(StringView locale)
|
||||
{
|
||||
if (auto hour_cycles = get_locale_hour_cycles(locale); !hour_cycles.is_empty())
|
||||
if (auto hour_cycles = TRY(get_locale_hour_cycles(locale)); !hour_cycles.is_empty())
|
||||
return hour_cycles.first();
|
||||
return {};
|
||||
return OptionalNone {};
|
||||
}
|
||||
|
||||
Optional<MinimumDaysRegion> __attribute__((weak)) minimum_days_region_from_string(StringView) { return {}; }
|
||||
Optional<u8> __attribute__((weak)) get_regional_minimum_days(StringView) { return {}; }
|
||||
|
||||
Optional<u8> get_locale_minimum_days(StringView locale)
|
||||
ErrorOr<Optional<u8>> get_locale_minimum_days(StringView locale)
|
||||
{
|
||||
return find_regional_values_for_locale(locale, get_regional_minimum_days);
|
||||
return find_regional_values_for_locale<Optional<u8>>(locale, get_regional_minimum_days);
|
||||
}
|
||||
|
||||
Optional<FirstDayRegion> __attribute__((weak)) first_day_region_from_string(StringView) { return {}; }
|
||||
Optional<Weekday> __attribute__((weak)) get_regional_first_day(StringView) { return {}; }
|
||||
|
||||
Optional<Weekday> get_locale_first_day(StringView locale)
|
||||
ErrorOr<Optional<Weekday>> get_locale_first_day(StringView locale)
|
||||
{
|
||||
return find_regional_values_for_locale(locale, get_regional_first_day);
|
||||
return find_regional_values_for_locale<Optional<Weekday>>(locale, get_regional_first_day);
|
||||
}
|
||||
|
||||
Optional<WeekendStartRegion> __attribute__((weak)) weekend_start_region_from_string(StringView) { return {}; }
|
||||
Optional<Weekday> __attribute__((weak)) get_regional_weekend_start(StringView) { return {}; }
|
||||
|
||||
Optional<Weekday> get_locale_weekend_start(StringView locale)
|
||||
ErrorOr<Optional<Weekday>> get_locale_weekend_start(StringView locale)
|
||||
{
|
||||
return find_regional_values_for_locale(locale, get_regional_weekend_start);
|
||||
return find_regional_values_for_locale<Optional<Weekday>>(locale, get_regional_weekend_start);
|
||||
}
|
||||
|
||||
Optional<WeekendEndRegion> __attribute__((weak)) weekend_end_region_from_string(StringView) { return {}; }
|
||||
Optional<Weekday> __attribute__((weak)) get_regional_weekend_end(StringView) { return {}; }
|
||||
|
||||
Optional<Weekday> get_locale_weekend_end(StringView locale)
|
||||
ErrorOr<Optional<Weekday>> get_locale_weekend_end(StringView locale)
|
||||
{
|
||||
return find_regional_values_for_locale(locale, get_regional_weekend_end);
|
||||
return find_regional_values_for_locale<Optional<Weekday>>(locale, get_regional_weekend_end);
|
||||
}
|
||||
|
||||
ErrorOr<String> combine_skeletons(StringView first, StringView second)
|
||||
|
@ -232,11 +232,11 @@ ErrorOr<Vector<CalendarPattern>> __attribute__((weak)) get_calendar_available_fo
|
|||
ErrorOr<Optional<CalendarRangePattern>> __attribute__((weak)) get_calendar_default_range_format(StringView, StringView) { return OptionalNone {}; }
|
||||
ErrorOr<Vector<CalendarRangePattern>> __attribute__((weak)) get_calendar_range_formats(StringView, StringView, StringView) { return Vector<CalendarRangePattern> {}; }
|
||||
ErrorOr<Vector<CalendarRangePattern>> __attribute__((weak)) get_calendar_range12_formats(StringView, StringView, StringView) { return Vector<CalendarRangePattern> {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_calendar_era_symbol(StringView, StringView, CalendarPatternStyle, Era) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_calendar_month_symbol(StringView, StringView, CalendarPatternStyle, Month) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_calendar_weekday_symbol(StringView, StringView, CalendarPatternStyle, Weekday) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_calendar_day_period_symbol(StringView, StringView, CalendarPatternStyle, DayPeriod) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_calendar_day_period_symbol_for_hour(StringView, StringView, CalendarPatternStyle, u8) { return {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_calendar_era_symbol(StringView, StringView, CalendarPatternStyle, Era) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_calendar_month_symbol(StringView, StringView, CalendarPatternStyle, Month) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_calendar_weekday_symbol(StringView, StringView, CalendarPatternStyle, Weekday) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_calendar_day_period_symbol(StringView, StringView, CalendarPatternStyle, DayPeriod) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_calendar_day_period_symbol_for_hour(StringView, StringView, CalendarPatternStyle, u8) { return OptionalNone {}; }
|
||||
|
||||
Optional<StringView> __attribute__((weak)) get_time_zone_name(StringView, StringView, CalendarPatternStyle, TimeZone::InDST) { return {}; }
|
||||
Optional<TimeZoneFormat> __attribute__((weak)) get_time_zone_format(StringView) { return {}; }
|
||||
|
@ -247,7 +247,7 @@ static ErrorOr<Optional<String>> format_time_zone_offset(StringView locale, Cale
|
|||
if (!formats.has_value())
|
||||
return OptionalNone {};
|
||||
|
||||
auto number_system = get_preferred_keyword_value_for_locale(locale, "nu"sv);
|
||||
auto number_system = TRY(get_preferred_keyword_value_for_locale(locale, "nu"sv));
|
||||
if (!number_system.has_value())
|
||||
return OptionalNone {};
|
||||
|
||||
|
|
|
@ -190,24 +190,24 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
|
|||
|
||||
Optional<HourCycleRegion> hour_cycle_region_from_string(StringView hour_cycle_region);
|
||||
Vector<HourCycle> get_regional_hour_cycles(StringView region);
|
||||
Vector<HourCycle> get_locale_hour_cycles(StringView locale);
|
||||
Optional<HourCycle> get_default_regional_hour_cycle(StringView locale);
|
||||
ErrorOr<Vector<HourCycle>> get_locale_hour_cycles(StringView locale);
|
||||
ErrorOr<Optional<HourCycle>> get_default_regional_hour_cycle(StringView locale);
|
||||
|
||||
Optional<MinimumDaysRegion> minimum_days_region_from_string(StringView minimum_days_region);
|
||||
Optional<u8> get_regional_minimum_days(StringView region);
|
||||
Optional<u8> get_locale_minimum_days(StringView region);
|
||||
ErrorOr<Optional<u8>> get_locale_minimum_days(StringView locale);
|
||||
|
||||
Optional<FirstDayRegion> first_day_region_from_string(StringView first_day_region);
|
||||
Optional<Weekday> get_regional_first_day(StringView region);
|
||||
Optional<Weekday> get_locale_first_day(StringView region);
|
||||
ErrorOr<Optional<Weekday>> get_locale_first_day(StringView locale);
|
||||
|
||||
Optional<WeekendStartRegion> weekend_start_region_from_string(StringView weekend_start_region);
|
||||
Optional<Weekday> get_regional_weekend_start(StringView region);
|
||||
Optional<Weekday> get_locale_weekend_start(StringView region);
|
||||
ErrorOr<Optional<Weekday>> get_locale_weekend_start(StringView locale);
|
||||
|
||||
Optional<WeekendEndRegion> weekend_end_region_from_string(StringView weekend_end_region);
|
||||
Optional<Weekday> get_regional_weekend_end(StringView region);
|
||||
Optional<Weekday> get_locale_weekend_end(StringView region);
|
||||
ErrorOr<Optional<Weekday>> get_locale_weekend_end(StringView locale);
|
||||
|
||||
ErrorOr<String> combine_skeletons(StringView first, StringView second);
|
||||
|
||||
|
@ -220,11 +220,11 @@ ErrorOr<Optional<CalendarRangePattern>> get_calendar_default_range_format(String
|
|||
ErrorOr<Vector<CalendarRangePattern>> get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton);
|
||||
ErrorOr<Vector<CalendarRangePattern>> get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton);
|
||||
|
||||
Optional<StringView> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value);
|
||||
Optional<StringView> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value);
|
||||
Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value);
|
||||
Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
|
||||
Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
|
||||
ErrorOr<Optional<StringView>> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value);
|
||||
ErrorOr<Optional<StringView>> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value);
|
||||
ErrorOr<Optional<StringView>> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value);
|
||||
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
|
||||
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
|
||||
|
||||
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);
|
||||
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style, TimeZone::InDST in_dst);
|
||||
|
|
|
@ -808,8 +808,8 @@ Optional<KeywordHours> __attribute__((weak)) keyword_hc_from_string(StringView)
|
|||
Optional<KeywordColCaseFirst> __attribute__((weak)) keyword_kf_from_string(StringView) { return {}; }
|
||||
Optional<KeywordColNumeric> __attribute__((weak)) keyword_kn_from_string(StringView) { return {}; }
|
||||
Optional<KeywordNumbers> __attribute__((weak)) keyword_nu_from_string(StringView) { return {}; }
|
||||
Vector<StringView> __attribute__((weak)) get_keywords_for_locale(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_preferred_keyword_value_for_locale(StringView, StringView) { return {}; }
|
||||
ErrorOr<Vector<StringView>> __attribute__((weak)) get_keywords_for_locale(StringView, StringView) { return Vector<StringView> {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_preferred_keyword_value_for_locale(StringView, StringView) { return OptionalNone {}; }
|
||||
Optional<DisplayPattern> __attribute__((weak)) get_locale_display_patterns(StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_language_mapping(StringView, StringView) { return {}; }
|
||||
Optional<StringView> __attribute__((weak)) get_locale_territory_mapping(StringView, StringView) { return {}; }
|
||||
|
|
|
@ -173,8 +173,8 @@ Optional<KeywordHours> keyword_hc_from_string(StringView hc);
|
|||
Optional<KeywordColCaseFirst> keyword_kf_from_string(StringView kf);
|
||||
Optional<KeywordColNumeric> keyword_kn_from_string(StringView kn);
|
||||
Optional<KeywordNumbers> keyword_nu_from_string(StringView nu);
|
||||
Vector<StringView> get_keywords_for_locale(StringView locale, StringView key);
|
||||
Optional<StringView> get_preferred_keyword_value_for_locale(StringView locale, StringView key);
|
||||
ErrorOr<Vector<StringView>> get_keywords_for_locale(StringView locale, StringView key);
|
||||
ErrorOr<Optional<StringView>> get_preferred_keyword_value_for_locale(StringView locale, StringView key);
|
||||
|
||||
Optional<DisplayPattern> get_locale_display_patterns(StringView locale);
|
||||
ErrorOr<Optional<String>> format_locale_for_display(StringView locale, LocaleID locale_id);
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
namespace Locale {
|
||||
|
||||
Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
|
||||
Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }
|
||||
Optional<NumberFormat> __attribute__((weak)) get_standard_number_system_format(StringView, StringView, StandardNumberFormatType) { return {}; }
|
||||
Vector<NumberFormat> __attribute__((weak)) get_compact_number_system_formats(StringView, StringView, CompactNumberFormatType) { return {}; }
|
||||
ErrorOr<Optional<StringView>> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<NumberGroupings>> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return OptionalNone {}; }
|
||||
ErrorOr<Optional<NumberFormat>> __attribute__((weak)) get_standard_number_system_format(StringView, StringView, StandardNumberFormatType) { return OptionalNone {}; }
|
||||
ErrorOr<Vector<NumberFormat>> __attribute__((weak)) get_compact_number_system_formats(StringView, StringView, CompactNumberFormatType) { return Vector<NumberFormat> {}; }
|
||||
Vector<NumberFormat> __attribute__((weak)) get_unit_formats(StringView, StringView, Style) { return {}; }
|
||||
|
||||
Optional<Span<u32 const>> __attribute__((weak)) get_digits_for_number_system(StringView)
|
||||
|
|
|
@ -61,14 +61,14 @@ enum class NumericSymbol : u8 {
|
|||
TimeSeparator,
|
||||
};
|
||||
|
||||
Optional<StringView> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol);
|
||||
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system);
|
||||
ErrorOr<Optional<StringView>> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol);
|
||||
ErrorOr<Optional<NumberGroupings>> get_number_system_groupings(StringView locale, StringView system);
|
||||
|
||||
Optional<Span<u32 const>> get_digits_for_number_system(StringView system);
|
||||
ErrorOr<String> replace_digits_for_number_system(StringView system, StringView number);
|
||||
|
||||
Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
|
||||
Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
|
||||
ErrorOr<Optional<NumberFormat>> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
|
||||
ErrorOr<Vector<NumberFormat>> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
|
||||
Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style);
|
||||
|
||||
ErrorOr<Optional<String>> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue