File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Userland/Libraries/LibUnicode Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 4
4
* SPDX-License-Identifier: BSD-2-Clause
5
5
*/
6
6
7
+ #include < AK/Array.h>
8
+ #include < AK/StringBuilder.h>
7
9
#include < LibUnicode/DateTimeFormat.h>
8
10
#include < LibUnicode/Locale.h>
9
11
@@ -113,6 +115,47 @@ Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale)
113
115
return {};
114
116
}
115
117
118
+ String combine_skeletons (StringView first, StringView second)
119
+ {
120
+ // https://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
121
+ constexpr auto field_order = Array {
122
+ " G" sv, // Era
123
+ " yYuUr" sv, // Year
124
+ " ML" sv, // Month
125
+ " dDFg" sv, // Day
126
+ " Eec" sv, // Weekday
127
+ " abB" sv, // Period
128
+ " hHKk" sv, // Hour
129
+ " m" sv, // Minute
130
+ " sSA" sv, // Second
131
+ " zZOvVXx" sv, // Zone
132
+ };
133
+
134
+ StringBuilder builder;
135
+
136
+ auto append_from_skeleton = [&](auto skeleton, auto ch) {
137
+ auto first_index = skeleton.find (ch);
138
+ if (!first_index.has_value ())
139
+ return false ;
140
+
141
+ auto last_index = skeleton.find_last (ch);
142
+
143
+ builder.append (skeleton.substring_view (*first_index, *last_index - *first_index + 1 ));
144
+ return true ;
145
+ };
146
+
147
+ for (auto fields : field_order) {
148
+ for (auto ch : fields) {
149
+ if (append_from_skeleton (first, ch))
150
+ break ;
151
+ if (append_from_skeleton (second, ch))
152
+ break ;
153
+ }
154
+ }
155
+
156
+ return builder.build ();
157
+ }
158
+
116
159
Optional<CalendarFormat> get_calendar_format ([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarFormatType type)
117
160
{
118
161
#if ENABLE_UNICODE_DATA
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ CalendarPatternStyle calendar_pattern_style_from_string(StringView style);
157
157
StringView calendar_pattern_style_to_string (CalendarPatternStyle style);
158
158
Vector<Unicode::HourCycle> get_regional_hour_cycles (StringView locale);
159
159
Optional<Unicode::HourCycle> get_default_regional_hour_cycle (StringView locale);
160
+ String combine_skeletons (StringView first, StringView second);
160
161
Optional<CalendarFormat> get_calendar_format (StringView locale, StringView calendar, CalendarFormatType type);
161
162
Vector<CalendarPattern> get_calendar_available_formats (StringView locale, StringView calendar);
162
163
Optional<Unicode::CalendarRangePattern> get_calendar_default_range_format (StringView locale, StringView calendar);
You can’t perform that action at this time.
0 commit comments