@@ -92,9 +92,9 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style)
92
92
}
93
93
94
94
Optional<HourCycleRegion> __attribute__ ((weak)) hour_cycle_region_from_string(StringView) { return {}; }
95
- Vector<HourCycle> __attribute__ ((weak)) get_regional_hour_cycles(StringView) { return {}; }
95
+ ErrorOr< Vector<HourCycle>> __attribute__ ((weak)) get_regional_hour_cycles(StringView) { return Vector<HourCycle> {}; }
96
96
97
- template <typename T, typename GetRegionalValues>
97
+ template <typename T, FallibleFunction<StringView> GetRegionalValues>
98
98
static ErrorOr<T> find_regional_values_for_locale (StringView locale, GetRegionalValues&& get_regional_values)
99
99
{
100
100
auto has_value = [](auto const & container) {
@@ -104,7 +104,7 @@ static ErrorOr<T> find_regional_values_for_locale(StringView locale, GetRegional
104
104
return !container.is_empty ();
105
105
};
106
106
107
- if (auto regional_values = get_regional_values (locale); has_value (regional_values))
107
+ if (auto regional_values = TRY ( get_regional_values (locale) ); has_value (regional_values))
108
108
return regional_values;
109
109
110
110
auto return_default_values = [&]() { return get_regional_values (" 001" sv); };
@@ -118,12 +118,18 @@ static ErrorOr<T> find_regional_values_for_locale(StringView locale, GetRegional
118
118
if (!language.has_value () || !language->region .has_value ())
119
119
return return_default_values ();
120
120
121
- if (auto regional_values = get_regional_values (*language->region ); has_value (regional_values))
121
+ if (auto regional_values = TRY ( get_regional_values (*language->region ) ); has_value (regional_values))
122
122
return regional_values;
123
123
124
124
return return_default_values ();
125
125
}
126
126
127
+ template <typename T, typename GetRegionalValues>
128
+ static ErrorOr<T> find_regional_values_for_locale (StringView locale, GetRegionalValues&& get_regional_values)
129
+ {
130
+ return find_regional_values_for_locale<T>(locale, [&](auto region) -> ErrorOr<T> { return get_regional_values (region); });
131
+ }
132
+
127
133
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
128
134
ErrorOr<Vector<HourCycle>> get_locale_hour_cycles (StringView locale)
129
135
{
@@ -187,22 +193,22 @@ ErrorOr<String> combine_skeletons(StringView first, StringView second)
187
193
188
194
StringBuilder builder;
189
195
190
- auto append_from_skeleton = [&](auto skeleton, auto ch) {
196
+ auto append_from_skeleton = [&](auto skeleton, auto ch) -> ErrorOr< bool > {
191
197
auto first_index = skeleton.find (ch);
192
198
if (!first_index.has_value ())
193
199
return false ;
194
200
195
201
auto last_index = skeleton.find_last (ch);
196
202
197
- builder.append (skeleton.substring_view (*first_index, *last_index - *first_index + 1 ));
203
+ TRY ( builder.try_append (skeleton.substring_view (*first_index, *last_index - *first_index + 1 ) ));
198
204
return true ;
199
205
};
200
206
201
207
for (auto fields : field_order) {
202
208
for (auto ch : fields) {
203
- if (append_from_skeleton (first, ch))
209
+ if (TRY ( append_from_skeleton (first, ch) ))
204
210
break ;
205
- if (append_from_skeleton (second, ch))
211
+ if (TRY ( append_from_skeleton (second, ch) ))
206
212
break ;
207
213
}
208
214
}
0 commit comments