mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
LibLocale: Rename a couple CLDR generator structures
When LibLocale is placed in the Locale namespace, this will conflict with the Locale structure in each CLDR generator. Rename this to "LocaleData", and rename its parent UnicodeLocaleData to just "CLDR" to avoid confusion between LocaleData and UnicodeLocaleData.
This commit is contained in:
parent
6c7b05a0ff
commit
88504b89e1
Notes:
sideshowbarker
2024-07-17 07:30:10 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/88504b89e1 Pull-request: https://github.com/SerenityOS/serenity/pull/15096 Reviewed-by: https://github.com/linusg ✅
@ -534,7 +534,7 @@ struct AK::Formatter<Unicode::HourCycle> : Formatter<FormatString> {
|
||||
}
|
||||
};
|
||||
|
||||
struct Locale {
|
||||
struct LocaleData {
|
||||
HashMap<String, CalendarIndexType> calendars;
|
||||
|
||||
TimeZoneNamesListIndexType time_zones { 0 };
|
||||
@ -543,7 +543,7 @@ struct Locale {
|
||||
DayPeriodListIndexType day_periods { 0 };
|
||||
};
|
||||
|
||||
struct UnicodeLocaleData {
|
||||
struct CLDR {
|
||||
UniqueStringStorage<StringIndexType> unique_strings;
|
||||
UniqueStorage<CalendarPattern, CalendarPatternIndexType> unique_patterns;
|
||||
UniqueStorage<CalendarPatternList, CalendarPatternListIndexType> unique_pattern_lists;
|
||||
@ -561,7 +561,7 @@ struct UnicodeLocaleData {
|
||||
UniqueStorage<DayPeriodList, DayPeriodListIndexType> unique_day_period_lists;
|
||||
UniqueStorage<HourCycleList, HourCycleListIndexType> unique_hour_cycle_lists;
|
||||
|
||||
HashMap<String, Locale> locales;
|
||||
HashMap<String, LocaleData> locales;
|
||||
|
||||
HashMap<String, HourCycleListIndexType> hour_cycles;
|
||||
Vector<String> hour_cycle_regions;
|
||||
@ -611,7 +611,7 @@ static Optional<Unicode::DayPeriod> day_period_from_string(StringView day_period
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_hour_cycles(String core_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_hour_cycles(String core_path, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Data
|
||||
LexicalPath time_data_path(move(core_path));
|
||||
@ -645,17 +645,17 @@ static ErrorOr<void> parse_hour_cycles(String core_path, UnicodeLocaleData& loca
|
||||
hour_cycles.append(*hour_cycle);
|
||||
}
|
||||
|
||||
auto hour_cycles_index = locale_data.unique_hour_cycle_lists.ensure(move(hour_cycles));
|
||||
locale_data.hour_cycles.set(key, hour_cycles_index);
|
||||
auto hour_cycles_index = cldr.unique_hour_cycle_lists.ensure(move(hour_cycles));
|
||||
cldr.hour_cycles.set(key, hour_cycles_index);
|
||||
|
||||
if (!locale_data.hour_cycle_regions.contains_slow(key))
|
||||
locale_data.hour_cycle_regions.append(key);
|
||||
if (!cldr.hour_cycle_regions.contains_slow(key))
|
||||
cldr.hour_cycle_regions.append(key);
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_week_data(String core_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_week_data(String core_path, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Week_Data
|
||||
LexicalPath week_data_path(move(core_path));
|
||||
@ -701,26 +701,26 @@ static ErrorOr<void> parse_week_data(String core_path, UnicodeLocaleData& locale
|
||||
|
||||
minimum_days_object.as_object().for_each_member([&](auto const& region, auto const& value) {
|
||||
auto minimum_days = value.as_string().template to_uint<u8>();
|
||||
locale_data.minimum_days.set(region, *minimum_days);
|
||||
cldr.minimum_days.set(region, *minimum_days);
|
||||
|
||||
if (!locale_data.minimum_days_regions.contains_slow(region))
|
||||
locale_data.minimum_days_regions.append(region);
|
||||
if (!cldr.minimum_days_regions.contains_slow(region))
|
||||
cldr.minimum_days_regions.append(region);
|
||||
});
|
||||
|
||||
first_day_object.as_object().for_each_member([&](auto const& region, auto const& value) {
|
||||
parse_regional_weekdays(region, value.as_string(), locale_data.first_day, locale_data.first_day_regions);
|
||||
parse_regional_weekdays(region, value.as_string(), cldr.first_day, cldr.first_day_regions);
|
||||
});
|
||||
weekend_start_object.as_object().for_each_member([&](auto const& region, auto const& value) {
|
||||
parse_regional_weekdays(region, value.as_string(), locale_data.weekend_start, locale_data.weekend_start_regions);
|
||||
parse_regional_weekdays(region, value.as_string(), cldr.weekend_start, cldr.weekend_start_regions);
|
||||
});
|
||||
weekend_end_object.as_object().for_each_member([&](auto const& region, auto const& value) {
|
||||
parse_regional_weekdays(region, value.as_string(), locale_data.weekend_end, locale_data.weekend_end_regions);
|
||||
parse_regional_weekdays(region, value.as_string(), cldr.weekend_end, cldr.weekend_end_regions);
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_meta_zones(String core_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_meta_zones(String core_path, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Metazones
|
||||
LexicalPath meta_zone_path(move(core_path));
|
||||
@ -738,14 +738,14 @@ static ErrorOr<void> parse_meta_zones(String core_path, UnicodeLocaleData& local
|
||||
auto const& golden_zone = mapping.as_object().get("_type"sv);
|
||||
|
||||
if (auto time_zone = TimeZone::time_zone_from_string(golden_zone.as_string()); time_zone.has_value()) {
|
||||
auto& golden_zones = locale_data.meta_zones.ensure(meta_zone.as_string());
|
||||
auto& golden_zones = cldr.meta_zones.ensure(meta_zone.as_string());
|
||||
golden_zones.append(*time_zone);
|
||||
}
|
||||
});
|
||||
|
||||
// UTC does not appear in metaZones.json. Define it for convenience so other parsers don't need to check for its existence.
|
||||
if (auto time_zone = TimeZone::time_zone_from_string("UTC"sv); time_zone.has_value())
|
||||
locale_data.meta_zones.set("UTC"sv, { *time_zone });
|
||||
cldr.meta_zones.set("UTC"sv, { *time_zone });
|
||||
|
||||
return {};
|
||||
}
|
||||
@ -800,7 +800,7 @@ static String remove_period_from_pattern(String pattern)
|
||||
return pattern;
|
||||
}
|
||||
|
||||
static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, String skeleton, UnicodeLocaleData& locale_data)
|
||||
static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, String skeleton, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
using Unicode::CalendarPatternStyle;
|
||||
@ -808,7 +808,7 @@ static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, Str
|
||||
CalendarPattern format {};
|
||||
|
||||
if (!skeleton.is_empty())
|
||||
format.skeleton_index = locale_data.unique_strings.ensure(move(skeleton));
|
||||
format.skeleton_index = cldr.unique_strings.ensure(move(skeleton));
|
||||
|
||||
GenericLexer lexer { pattern };
|
||||
StringBuilder builder;
|
||||
@ -1019,18 +1019,18 @@ static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, Str
|
||||
return format;
|
||||
}
|
||||
|
||||
static Optional<CalendarPatternIndexType> parse_date_time_pattern(String pattern, String skeleton, UnicodeLocaleData& locale_data)
|
||||
static Optional<CalendarPatternIndexType> parse_date_time_pattern(String pattern, String skeleton, CLDR& cldr)
|
||||
{
|
||||
auto format = parse_date_time_pattern_raw(move(pattern), move(skeleton), locale_data);
|
||||
auto format = parse_date_time_pattern_raw(move(pattern), move(skeleton), cldr);
|
||||
if (!format.has_value())
|
||||
return {};
|
||||
|
||||
format->pattern_index = locale_data.unique_strings.ensure(move(format->pattern));
|
||||
format->pattern_index = cldr.unique_strings.ensure(move(format->pattern));
|
||||
|
||||
if (format->pattern12.has_value())
|
||||
format->pattern12_index = locale_data.unique_strings.ensure(format->pattern12.release_value());
|
||||
format->pattern12_index = cldr.unique_strings.ensure(format->pattern12.release_value());
|
||||
|
||||
return locale_data.unique_patterns.ensure(format.release_value());
|
||||
return cldr.unique_patterns.ensure(format.release_value());
|
||||
}
|
||||
|
||||
template<typename... Chars>
|
||||
@ -1039,7 +1039,7 @@ static constexpr bool char_is_one_of(char ch, Chars&&... chars)
|
||||
return ((ch == chars) || ...);
|
||||
}
|
||||
|
||||
static void parse_interval_patterns(Calendar& calendar, JsonObject const& interval_formats_object, UnicodeLocaleData& locale_data)
|
||||
static void parse_interval_patterns(Calendar& calendar, JsonObject const& interval_formats_object, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats
|
||||
CalendarRangePatternList range_formats {};
|
||||
@ -1079,10 +1079,10 @@ static void parse_interval_patterns(Calendar& calendar, JsonObject const& interv
|
||||
auto end_range = pattern.substring_view(end_range_begin);
|
||||
|
||||
CalendarRangePattern format {};
|
||||
format.skeleton_index = locale_data.unique_strings.ensure(skeleton);
|
||||
format.start_range = locale_data.unique_strings.ensure(start_range);
|
||||
format.separator = locale_data.unique_strings.ensure(separator);
|
||||
format.end_range = locale_data.unique_strings.ensure(end_range);
|
||||
format.skeleton_index = cldr.unique_strings.ensure(skeleton);
|
||||
format.start_range = cldr.unique_strings.ensure(start_range);
|
||||
format.separator = cldr.unique_strings.ensure(separator);
|
||||
format.end_range = cldr.unique_strings.ensure(end_range);
|
||||
|
||||
return format;
|
||||
};
|
||||
@ -1115,11 +1115,11 @@ static void parse_interval_patterns(Calendar& calendar, JsonObject const& interv
|
||||
auto end_range = pattern.substring_view(*begin_index);
|
||||
|
||||
CalendarRangePattern format {};
|
||||
format.skeleton_index = locale_data.unique_strings.ensure(skeleton);
|
||||
format.skeleton_index = cldr.unique_strings.ensure(skeleton);
|
||||
format.field = field;
|
||||
format.start_range = locale_data.unique_strings.ensure(start_range);
|
||||
format.separator = locale_data.unique_strings.ensure(separator);
|
||||
format.end_range = locale_data.unique_strings.ensure(end_range);
|
||||
format.start_range = cldr.unique_strings.ensure(start_range);
|
||||
format.separator = cldr.unique_strings.ensure(separator);
|
||||
format.end_range = cldr.unique_strings.ensure(end_range);
|
||||
|
||||
format.for_each_calendar_field_zipped_with(parsed_fields, [](auto& format_field, auto const& parsed_field, auto) {
|
||||
format_field = parsed_field;
|
||||
@ -1131,7 +1131,7 @@ static void parse_interval_patterns(Calendar& calendar, JsonObject const& interv
|
||||
interval_formats_object.for_each_member([&](auto const& skeleton, auto const& value) {
|
||||
if (skeleton == "intervalFormatFallback"sv) {
|
||||
auto range_format = split_default_range_pattern(skeleton, value.as_string());
|
||||
calendar.default_range_format = locale_data.unique_range_patterns.ensure(move(range_format));
|
||||
calendar.default_range_format = cldr.unique_range_patterns.ensure(move(range_format));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1142,32 +1142,32 @@ static void parse_interval_patterns(Calendar& calendar, JsonObject const& interv
|
||||
VERIFY(field.length() == 1);
|
||||
auto name = name_of_field(field[0]);
|
||||
|
||||
auto format = parse_date_time_pattern_raw(pattern.as_string(), skeleton, locale_data).release_value();
|
||||
auto format = parse_date_time_pattern_raw(pattern.as_string(), skeleton, cldr).release_value();
|
||||
|
||||
auto range_format = split_range_pattern(skeleton, name, format.pattern, format);
|
||||
range_formats.append(locale_data.unique_range_patterns.ensure(move(range_format)));
|
||||
range_formats.append(cldr.unique_range_patterns.ensure(move(range_format)));
|
||||
|
||||
if (format.pattern12.has_value()) {
|
||||
auto range12_pattern = split_range_pattern(skeleton, name, *format.pattern12, format);
|
||||
range12_formats.append(locale_data.unique_range_patterns.ensure(move(range12_pattern)));
|
||||
range12_formats.append(cldr.unique_range_patterns.ensure(move(range12_pattern)));
|
||||
} else {
|
||||
range12_formats.append(range_formats.last());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
calendar.range_formats = locale_data.unique_range_pattern_lists.ensure(move(range_formats));
|
||||
calendar.range12_formats = locale_data.unique_range_pattern_lists.ensure(move(range12_formats));
|
||||
calendar.range_formats = cldr.unique_range_pattern_lists.ensure(move(range_formats));
|
||||
calendar.range12_formats = cldr.unique_range_pattern_lists.ensure(move(range12_formats));
|
||||
}
|
||||
|
||||
static void generate_default_patterns(CalendarPatternList& formats, UnicodeLocaleData& locale_data)
|
||||
static void generate_default_patterns(CalendarPatternList& formats, CLDR& cldr)
|
||||
{
|
||||
// For compatibility with ICU, we generate a list of default patterns for every locale:
|
||||
// https://github.com/unicode-org/icu/blob/release-71-1/icu4c/source/i18n/dtptngen.cpp#L1343-L1354=
|
||||
static constexpr auto default_patterns = Array { "G"sv, "y"sv, "M"sv, "E"sv, "D"sv, "F"sv, "d"sv, "a"sv, "B"sv, "H"sv, "mm"sv, "ss"sv, "SS"sv, "v"sv };
|
||||
|
||||
for (auto pattern : default_patterns) {
|
||||
auto index = parse_date_time_pattern(pattern, pattern, locale_data);
|
||||
auto index = parse_date_time_pattern(pattern, pattern, cldr);
|
||||
VERIFY(index.has_value());
|
||||
|
||||
if (!formats.contains_slow(*index))
|
||||
@ -1175,27 +1175,27 @@ static void generate_default_patterns(CalendarPatternList& formats, UnicodeLocal
|
||||
}
|
||||
}
|
||||
|
||||
static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& formats, Vector<CalendarPattern> date_formats, Vector<CalendarPattern> time_formats, UnicodeLocaleData& locale_data)
|
||||
static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& formats, Vector<CalendarPattern> date_formats, Vector<CalendarPattern> time_formats, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Missing_Skeleton_Fields
|
||||
auto replace_pattern = [&](auto format, auto time_format, auto date_format) {
|
||||
auto pattern = locale_data.unique_strings.get(format);
|
||||
auto time_pattern = locale_data.unique_strings.get(time_format);
|
||||
auto date_pattern = locale_data.unique_strings.get(date_format);
|
||||
auto pattern = cldr.unique_strings.get(format);
|
||||
auto time_pattern = cldr.unique_strings.get(time_format);
|
||||
auto date_pattern = cldr.unique_strings.get(date_format);
|
||||
|
||||
auto new_pattern = pattern.replace("{0}"sv, time_pattern, ReplaceMode::FirstOnly).replace("{1}"sv, date_pattern, ReplaceMode::FirstOnly);
|
||||
return locale_data.unique_strings.ensure(move(new_pattern));
|
||||
return cldr.unique_strings.ensure(move(new_pattern));
|
||||
};
|
||||
|
||||
auto inject_fractional_second_digits = [&](auto format) {
|
||||
auto pattern = locale_data.unique_strings.get(format);
|
||||
auto pattern = cldr.unique_strings.get(format);
|
||||
|
||||
auto new_pattern = pattern.replace("{second}"sv, "{second}{decimal}{fractionalSecondDigits}"sv, ReplaceMode::FirstOnly);
|
||||
return locale_data.unique_strings.ensure(move(new_pattern));
|
||||
return cldr.unique_strings.ensure(move(new_pattern));
|
||||
};
|
||||
|
||||
auto append_if_unique = [&](auto format) {
|
||||
auto format_index = locale_data.unique_patterns.ensure(move(format));
|
||||
auto format_index = cldr.unique_patterns.ensure(move(format));
|
||||
|
||||
if (!formats.contains_slow(format_index))
|
||||
formats.append(format_index);
|
||||
@ -1224,7 +1224,7 @@ static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& f
|
||||
time_formats.extend(move(time_formats_with_fractional_second_digits));
|
||||
|
||||
for (auto const& date_format : date_formats) {
|
||||
auto const& date_time_formats = locale_data.unique_formats.get(calendar.date_time_formats);
|
||||
auto const& date_time_formats = cldr.unique_formats.get(calendar.date_time_formats);
|
||||
CalendarPatternIndexType date_time_format_index = 0;
|
||||
|
||||
if (date_format.month == Unicode::CalendarPatternStyle::Long) {
|
||||
@ -1239,7 +1239,7 @@ static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& f
|
||||
}
|
||||
|
||||
for (auto const& time_format : time_formats) {
|
||||
auto format = locale_data.unique_patterns.get(date_time_format_index);
|
||||
auto format = cldr.unique_patterns.get(date_time_format_index);
|
||||
|
||||
if (time_format.pattern12_index != 0)
|
||||
format.pattern12_index = replace_pattern(format.pattern_index, time_format.pattern12_index, date_format.pattern_index);
|
||||
@ -1259,7 +1259,7 @@ static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& f
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calendar_object, UnicodeLocaleData& locale_data)
|
||||
static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calendar_object, CLDR& cldr)
|
||||
{
|
||||
auto create_symbol_lists = [](size_t size) {
|
||||
SymbolList narrow_symbol_list;
|
||||
@ -1285,11 +1285,11 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
symbols_list.resize(symbol_index + 1);
|
||||
|
||||
CalendarSymbols symbols {};
|
||||
symbols.narrow_symbols = locale_data.unique_symbol_lists.ensure(move(symbol_lists[0]));
|
||||
symbols.short_symbols = locale_data.unique_symbol_lists.ensure(move(symbol_lists[1]));
|
||||
symbols.long_symbols = locale_data.unique_symbol_lists.ensure(move(symbol_lists[2]));
|
||||
symbols.narrow_symbols = cldr.unique_symbol_lists.ensure(move(symbol_lists[0]));
|
||||
symbols.short_symbols = cldr.unique_symbol_lists.ensure(move(symbol_lists[1]));
|
||||
symbols.long_symbols = cldr.unique_symbol_lists.ensure(move(symbol_lists[2]));
|
||||
|
||||
auto calendar_symbols_index = locale_data.unique_calendar_symbols.ensure(move(symbols));
|
||||
auto calendar_symbols_index = cldr.unique_calendar_symbols.ensure(move(symbols));
|
||||
symbols_list[symbol_index] = calendar_symbols_index;
|
||||
};
|
||||
|
||||
@ -1301,7 +1301,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
if (auto key_index = key.to_uint(); key_index.has_value())
|
||||
symbols[*key_index] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[*key_index] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||
@ -1325,7 +1325,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
auto key_index = key.to_uint().value() - 1;
|
||||
symbols[key_index] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[key_index] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||
@ -1349,19 +1349,19 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
if (key == "sun"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Sunday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Sunday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "mon"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Monday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Monday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "tue"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Tuesday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Tuesday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "wed"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Wednesday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Wednesday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "thu"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Thursday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Thursday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "fri"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Friday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Friday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
else if (key == "sat"sv)
|
||||
symbols[to_underlying(Unicode::Weekday::Saturday)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(Unicode::Weekday::Saturday)] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||
@ -1385,7 +1385,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
|
||||
auto append_symbol = [&](auto& symbols, auto const& key, auto symbol) {
|
||||
if (auto day_period = day_period_from_string(key); day_period.has_value())
|
||||
symbols[to_underlying(*day_period)] = locale_data.unique_strings.ensure(move(symbol));
|
||||
symbols[to_underlying(*day_period)] = cldr.unique_strings.ensure(move(symbol));
|
||||
};
|
||||
|
||||
narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||
@ -1406,10 +1406,10 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||
parse_weekday_symbols(calendar_object.get("days"sv).as_object().get("format"sv).as_object());
|
||||
parse_day_period_symbols(calendar_object.get("dayPeriods"sv).as_object().get("format"sv).as_object());
|
||||
|
||||
calendar.symbols = locale_data.unique_calendar_symbols_lists.ensure(move(symbols_list));
|
||||
calendar.symbols = cldr.unique_calendar_symbols_lists.ensure(move(symbols_list));
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocaleData& locale_data, Locale& locale)
|
||||
static ErrorOr<void> parse_calendars(String locale_calendars_path, CLDR& cldr, LocaleData& locale)
|
||||
{
|
||||
LexicalPath calendars_path(move(locale_calendars_path));
|
||||
if (!calendars_path.basename().starts_with("ca-"sv))
|
||||
@ -1426,10 +1426,10 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocale
|
||||
auto format = patterns_object.get(name);
|
||||
auto skeleton = skeletons_object.get(name);
|
||||
|
||||
auto format_index = parse_date_time_pattern(format.as_string(), skeleton.as_string_or(String::empty()), locale_data).value();
|
||||
auto format_index = parse_date_time_pattern(format.as_string(), skeleton.as_string_or(String::empty()), cldr).value();
|
||||
|
||||
if (patterns)
|
||||
patterns->append(locale_data.unique_patterns.get(format_index));
|
||||
patterns->append(cldr.unique_patterns.get(format_index));
|
||||
|
||||
return format_index;
|
||||
};
|
||||
@ -1440,7 +1440,7 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocale
|
||||
formats.medium_format = parse_pattern("medium"sv);
|
||||
formats.short_format = parse_pattern("short"sv);
|
||||
|
||||
return locale_data.unique_formats.ensure(move(formats));
|
||||
return cldr.unique_formats.ensure(move(formats));
|
||||
};
|
||||
|
||||
calendars_object.as_object().for_each_member([&](auto const& calendar_name, JsonValue const& value) {
|
||||
@ -1452,8 +1452,8 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocale
|
||||
Calendar calendar {};
|
||||
CalendarPatternList available_formats {};
|
||||
|
||||
if (!locale_data.calendars.contains_slow(calendar_name))
|
||||
locale_data.calendars.append(calendar_name);
|
||||
if (!cldr.calendars.contains_slow(calendar_name))
|
||||
cldr.calendars.append(calendar_name);
|
||||
|
||||
Vector<CalendarPattern> date_formats;
|
||||
Vector<CalendarPattern> time_formats;
|
||||
@ -1471,11 +1471,11 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocale
|
||||
|
||||
auto const& available_formats_object = date_time_formats_object.as_object().get("availableFormats"sv);
|
||||
available_formats_object.as_object().for_each_member([&](auto const& skeleton, JsonValue const& pattern) {
|
||||
auto pattern_index = parse_date_time_pattern(pattern.as_string(), skeleton, locale_data);
|
||||
auto pattern_index = parse_date_time_pattern(pattern.as_string(), skeleton, cldr);
|
||||
if (!pattern_index.has_value())
|
||||
return;
|
||||
|
||||
auto const& format = locale_data.unique_patterns.get(*pattern_index);
|
||||
auto const& format = cldr.unique_patterns.get(*pattern_index);
|
||||
if (format.contains_only_date_fields())
|
||||
date_formats.append(format);
|
||||
else if (format.contains_only_time_fields())
|
||||
@ -1486,20 +1486,20 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, UnicodeLocale
|
||||
});
|
||||
|
||||
auto const& interval_formats_object = date_time_formats_object.as_object().get("intervalFormats"sv);
|
||||
parse_interval_patterns(calendar, interval_formats_object.as_object(), locale_data);
|
||||
parse_interval_patterns(calendar, interval_formats_object.as_object(), cldr);
|
||||
|
||||
generate_default_patterns(available_formats, locale_data);
|
||||
generate_missing_patterns(calendar, available_formats, move(date_formats), move(time_formats), locale_data);
|
||||
parse_calendar_symbols(calendar, value.as_object(), locale_data);
|
||||
generate_default_patterns(available_formats, cldr);
|
||||
generate_missing_patterns(calendar, available_formats, move(date_formats), move(time_formats), cldr);
|
||||
parse_calendar_symbols(calendar, value.as_object(), cldr);
|
||||
|
||||
calendar.available_formats = locale_data.unique_pattern_lists.ensure(move(available_formats));
|
||||
locale.calendars.set(calendar_name, locale_data.unique_calendars.ensure(move(calendar)));
|
||||
calendar.available_formats = cldr.unique_pattern_lists.ensure(move(available_formats));
|
||||
locale.calendars.set(calendar_name, cldr.unique_calendars.ensure(move(calendar)));
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, UnicodeLocaleData& locale_data, Locale& locale)
|
||||
static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
|
||||
{
|
||||
LexicalPath time_zone_names_path(move(locale_time_zone_names_path));
|
||||
time_zone_names_path = time_zone_names_path.append("timeZoneNames.json"sv);
|
||||
@ -1524,7 +1524,7 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, U
|
||||
|
||||
auto const& name = names.as_object().get(key);
|
||||
if (name.is_string())
|
||||
return locale_data.unique_strings.ensure(name.as_string());
|
||||
return cldr.unique_strings.ensure(name.as_string());
|
||||
|
||||
return {};
|
||||
};
|
||||
@ -1546,22 +1546,22 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, U
|
||||
auto symbol_behind_sign = hour_formats[1].substring_view(0, hour_format_behind_start);
|
||||
auto symbol_behind_separator = hour_formats[1].substring_view(separator_behind_start, separator_behind_end - separator_behind_start);
|
||||
|
||||
time_zone_formats.symbol_ahead_sign = locale_data.unique_strings.ensure(symbol_ahead_sign);
|
||||
time_zone_formats.symbol_ahead_separator = locale_data.unique_strings.ensure(symbol_ahead_separator);
|
||||
time_zone_formats.symbol_behind_sign = locale_data.unique_strings.ensure(symbol_behind_sign);
|
||||
time_zone_formats.symbol_behind_separator = locale_data.unique_strings.ensure(symbol_behind_separator);
|
||||
time_zone_formats.symbol_ahead_sign = cldr.unique_strings.ensure(symbol_ahead_sign);
|
||||
time_zone_formats.symbol_ahead_separator = cldr.unique_strings.ensure(symbol_ahead_separator);
|
||||
time_zone_formats.symbol_behind_sign = cldr.unique_strings.ensure(symbol_behind_sign);
|
||||
time_zone_formats.symbol_behind_separator = cldr.unique_strings.ensure(symbol_behind_separator);
|
||||
};
|
||||
|
||||
TimeZoneNamesList time_zones;
|
||||
|
||||
TimeZoneFormat time_zone_formats {};
|
||||
parse_hour_format(hour_format_string.as_string(), time_zone_formats);
|
||||
time_zone_formats.gmt_format = locale_data.unique_strings.ensure(gmt_format_string.as_string());
|
||||
time_zone_formats.gmt_zero_format = locale_data.unique_strings.ensure(gmt_zero_format_string.as_string());
|
||||
time_zone_formats.gmt_format = cldr.unique_strings.ensure(gmt_format_string.as_string());
|
||||
time_zone_formats.gmt_zero_format = cldr.unique_strings.ensure(gmt_zero_format_string.as_string());
|
||||
|
||||
auto parse_time_zone = [&](StringView meta_zone, JsonObject const& meta_zone_object) {
|
||||
auto golden_zones = locale_data.meta_zones.find(meta_zone);
|
||||
if (golden_zones == locale_data.meta_zones.end())
|
||||
auto golden_zones = cldr.meta_zones.find(meta_zone);
|
||||
if (golden_zones == cldr.meta_zones.end())
|
||||
return;
|
||||
|
||||
TimeZoneNames time_zone_names {};
|
||||
@ -1581,7 +1581,7 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, U
|
||||
if (auto name = parse_name("short"sv, meta_zone_object, "generic"sv); name.has_value())
|
||||
time_zone_names.short_generic_name = name.value();
|
||||
|
||||
auto time_zone_index = locale_data.unique_time_zones.ensure(move(time_zone_names));
|
||||
auto time_zone_index = cldr.unique_time_zones.ensure(move(time_zone_names));
|
||||
|
||||
for (auto golden_zone : golden_zones->value) {
|
||||
auto time_zone = to_underlying(golden_zone);
|
||||
@ -1602,13 +1602,13 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, U
|
||||
auto const& utc_object = etc_object.as_object().get("UTC"sv);
|
||||
parse_time_zone("UTC"sv, utc_object.as_object());
|
||||
|
||||
locale.time_zones = locale_data.unique_time_zone_lists.ensure(move(time_zones));
|
||||
locale.time_zone_formats = locale_data.unique_time_zone_formats.ensure(move(time_zone_formats));
|
||||
locale.time_zones = cldr.unique_time_zone_lists.ensure(move(time_zones));
|
||||
locale.time_zone_formats = cldr.unique_time_zone_formats.ensure(move(time_zone_formats));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_day_periods(String core_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_day_periods(String core_path, CLDR& cldr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rule_Sets
|
||||
LexicalPath day_periods_path(move(core_path));
|
||||
@ -1645,41 +1645,41 @@ static ErrorOr<void> parse_day_periods(String core_path, UnicodeLocaleData& loca
|
||||
};
|
||||
|
||||
day_periods_object.as_object().for_each_member([&](auto const& language, JsonValue const& value) {
|
||||
auto locale = locale_data.locales.find(language);
|
||||
if (locale == locale_data.locales.end())
|
||||
auto locale = cldr.locales.find(language);
|
||||
if (locale == cldr.locales.end())
|
||||
return;
|
||||
|
||||
DayPeriodList day_periods;
|
||||
|
||||
value.as_object().for_each_member([&](auto const& symbol, JsonValue const& ranges) {
|
||||
if (auto day_period = parse_day_period(symbol, ranges.as_object()); day_period.has_value()) {
|
||||
auto day_period_index = locale_data.unique_day_periods.ensure(day_period.release_value());
|
||||
auto day_period_index = cldr.unique_day_periods.ensure(day_period.release_value());
|
||||
day_periods.append(day_period_index);
|
||||
}
|
||||
});
|
||||
|
||||
locale->value.day_periods = locale_data.unique_day_period_lists.ensure(move(day_periods));
|
||||
locale->value.day_periods = cldr.unique_day_period_lists.ensure(move(day_periods));
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String dates_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String dates_path, CLDR& cldr)
|
||||
{
|
||||
TRY(parse_hour_cycles(core_path, locale_data));
|
||||
TRY(parse_week_data(core_path, locale_data));
|
||||
TRY(parse_meta_zones(core_path, locale_data));
|
||||
TRY(parse_hour_cycles(core_path, cldr));
|
||||
TRY(parse_week_data(core_path, cldr));
|
||||
TRY(parse_meta_zones(core_path, cldr));
|
||||
|
||||
auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
|
||||
|
||||
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(locale_data.unique_strings, LexicalPath::basename(path)));
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(locale_data.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = locale_data.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.append(cldr.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = cldr.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.appendff("-{}", script);
|
||||
if (auto region = locale_data.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
builder.appendff("-{}", region);
|
||||
|
||||
return builder.build();
|
||||
@ -1690,17 +1690,17 @@ static ErrorOr<void> parse_all_locales(String core_path, String dates_path, Unic
|
||||
auto calendars_iterator = TRY(path_to_dir_iterator(dates_path, {}));
|
||||
|
||||
auto language = TRY(remove_variants_from_path(dates_path));
|
||||
auto& locale = locale_data.locales.ensure(language);
|
||||
auto& locale = cldr.locales.ensure(language);
|
||||
|
||||
while (calendars_iterator.has_next()) {
|
||||
auto calendars_path = TRY(next_path_from_dir_iterator(calendars_iterator));
|
||||
TRY(parse_calendars(move(calendars_path), locale_data, locale));
|
||||
TRY(parse_calendars(move(calendars_path), cldr, locale));
|
||||
}
|
||||
|
||||
TRY(parse_time_zone_names(move(dates_path), locale_data, locale));
|
||||
TRY(parse_time_zone_names(move(dates_path), cldr, locale));
|
||||
}
|
||||
|
||||
TRY(parse_day_periods(move(core_path), locale_data));
|
||||
TRY(parse_day_periods(move(core_path), cldr));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -1716,7 +1716,7 @@ static String format_identifier(StringView owner, String identifier)
|
||||
return identifier;
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -1729,12 +1729,12 @@ static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile&
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
generate_enum(generator, format_identifier, "Calendar"sv, {}, locale_data.calendars);
|
||||
generate_enum(generator, format_identifier, "HourCycleRegion"sv, {}, locale_data.hour_cycle_regions);
|
||||
generate_enum(generator, format_identifier, "MinimumDaysRegion"sv, {}, locale_data.minimum_days_regions);
|
||||
generate_enum(generator, format_identifier, "FirstDayRegion"sv, {}, locale_data.first_day_regions);
|
||||
generate_enum(generator, format_identifier, "WeekendStartRegion"sv, {}, locale_data.weekend_start_regions);
|
||||
generate_enum(generator, format_identifier, "WeekendEndRegion"sv, {}, locale_data.weekend_end_regions);
|
||||
generate_enum(generator, format_identifier, "Calendar"sv, {}, cldr.calendars);
|
||||
generate_enum(generator, format_identifier, "HourCycleRegion"sv, {}, cldr.hour_cycle_regions);
|
||||
generate_enum(generator, format_identifier, "MinimumDaysRegion"sv, {}, cldr.minimum_days_regions);
|
||||
generate_enum(generator, format_identifier, "FirstDayRegion"sv, {}, cldr.first_day_regions);
|
||||
generate_enum(generator, format_identifier, "WeekendStartRegion"sv, {}, cldr.weekend_start_regions);
|
||||
generate_enum(generator, format_identifier, "WeekendEndRegion"sv, {}, cldr.weekend_end_regions);
|
||||
|
||||
generator.append(R"~~~(
|
||||
}
|
||||
@ -1744,7 +1744,7 @@ namespace Unicode {
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -1777,7 +1777,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_strings.generate(generator);
|
||||
cldr.unique_strings.generate(generator);
|
||||
|
||||
generator.append(R"~~~(
|
||||
template <typename SourceType, typename TargetType>
|
||||
@ -1871,10 +1871,10 @@ struct CalendarRangePatternImpl {
|
||||
};
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_patterns.generate(generator, "CalendarPatternImpl"sv, "s_calendar_patterns"sv, 10);
|
||||
locale_data.unique_pattern_lists.generate(generator, s_calendar_pattern_index_type, "s_calendar_pattern_lists"sv);
|
||||
locale_data.unique_range_patterns.generate(generator, "CalendarRangePatternImpl"sv, "s_calendar_range_patterns"sv, 10);
|
||||
locale_data.unique_range_pattern_lists.generate(generator, s_calendar_range_pattern_index_type, "s_calendar_range_pattern_lists"sv);
|
||||
cldr.unique_patterns.generate(generator, "CalendarPatternImpl"sv, "s_calendar_patterns"sv, 10);
|
||||
cldr.unique_pattern_lists.generate(generator, s_calendar_pattern_index_type, "s_calendar_pattern_lists"sv);
|
||||
cldr.unique_range_patterns.generate(generator, "CalendarRangePatternImpl"sv, "s_calendar_range_patterns"sv, 10);
|
||||
cldr.unique_range_pattern_lists.generate(generator, s_calendar_range_pattern_index_type, "s_calendar_range_pattern_lists"sv);
|
||||
|
||||
generator.append(R"~~~(
|
||||
struct CalendarFormatImpl {
|
||||
@ -1956,17 +1956,17 @@ struct DayPeriodData {
|
||||
};
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_formats.generate(generator, "CalendarFormatImpl"sv, "s_calendar_formats"sv, 10);
|
||||
locale_data.unique_symbol_lists.generate(generator, s_string_index_type, "s_symbol_lists"sv);
|
||||
locale_data.unique_calendar_symbols.generate(generator, "CalendarSymbols"sv, "s_calendar_symbols"sv, 10);
|
||||
locale_data.unique_calendar_symbols_lists.generate(generator, s_calendar_symbols_index_type, "s_calendar_symbol_lists"sv);
|
||||
locale_data.unique_calendars.generate(generator, "CalendarData"sv, "s_calendars"sv, 10);
|
||||
locale_data.unique_time_zones.generate(generator, "TimeZoneNames"sv, "s_time_zones"sv, 30);
|
||||
locale_data.unique_time_zone_lists.generate(generator, s_time_zone_index_type, "s_time_zone_lists"sv);
|
||||
locale_data.unique_time_zone_formats.generate(generator, "TimeZoneFormatImpl"sv, "s_time_zone_formats"sv, 30);
|
||||
locale_data.unique_day_periods.generate(generator, "DayPeriodData"sv, "s_day_periods"sv, 30);
|
||||
locale_data.unique_day_period_lists.generate(generator, s_day_period_index_type, "s_day_period_lists"sv);
|
||||
locale_data.unique_hour_cycle_lists.generate(generator, "u8"sv, "s_hour_cycle_lists"sv);
|
||||
cldr.unique_formats.generate(generator, "CalendarFormatImpl"sv, "s_calendar_formats"sv, 10);
|
||||
cldr.unique_symbol_lists.generate(generator, s_string_index_type, "s_symbol_lists"sv);
|
||||
cldr.unique_calendar_symbols.generate(generator, "CalendarSymbols"sv, "s_calendar_symbols"sv, 10);
|
||||
cldr.unique_calendar_symbols_lists.generate(generator, s_calendar_symbols_index_type, "s_calendar_symbol_lists"sv);
|
||||
cldr.unique_calendars.generate(generator, "CalendarData"sv, "s_calendars"sv, 10);
|
||||
cldr.unique_time_zones.generate(generator, "TimeZoneNames"sv, "s_time_zones"sv, 30);
|
||||
cldr.unique_time_zone_lists.generate(generator, s_time_zone_index_type, "s_time_zone_lists"sv);
|
||||
cldr.unique_time_zone_formats.generate(generator, "TimeZoneFormatImpl"sv, "s_time_zone_formats"sv, 30);
|
||||
cldr.unique_day_periods.generate(generator, "DayPeriodData"sv, "s_day_periods"sv, 30);
|
||||
cldr.unique_day_period_lists.generate(generator, s_day_period_index_type, "s_day_period_lists"sv);
|
||||
cldr.unique_hour_cycle_lists.generate(generator, "u8"sv, "s_hour_cycle_lists"sv);
|
||||
|
||||
auto append_calendars = [&](String name, auto const& calendars) {
|
||||
generator.set("name", name);
|
||||
@ -1976,7 +1976,7 @@ struct DayPeriodData {
|
||||
static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
|
||||
|
||||
bool first = true;
|
||||
for (auto const& calendar_key : locale_data.calendars) {
|
||||
for (auto const& calendar_key : cldr.calendars) {
|
||||
auto calendar = calendars.find(calendar_key)->value;
|
||||
|
||||
generator.append(first ? " "sv : ", "sv);
|
||||
@ -2008,18 +2008,18 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||
generator.append(" } };");
|
||||
};
|
||||
|
||||
auto locales = locale_data.locales.keys();
|
||||
auto locales = cldr.locales.keys();
|
||||
quick_sort(locales);
|
||||
|
||||
generate_mapping(generator, locale_data.locales, s_calendar_index_type, "s_locale_calendars"sv, "s_calendars_{}"sv, format_identifier, [&](auto const& name, auto const& value) { append_calendars(name, value.calendars); });
|
||||
append_mapping(locales, locale_data.locales, s_time_zone_index_type, "s_locale_time_zones"sv, [](auto const& locale) { return locale.time_zones; });
|
||||
append_mapping(locales, locale_data.locales, s_time_zone_format_index_type, "s_locale_time_zone_formats"sv, [](auto const& locale) { return locale.time_zone_formats; });
|
||||
append_mapping(locales, locale_data.locales, s_day_period_index_type, "s_locale_day_periods"sv, [](auto const& locale) { return locale.day_periods; });
|
||||
append_mapping(locale_data.hour_cycle_regions, locale_data.hour_cycles, s_hour_cycle_list_index_type, "s_hour_cycles"sv, [](auto const& hour_cycles) { return hour_cycles; });
|
||||
append_mapping(locale_data.minimum_days_regions, locale_data.minimum_days, "u8"sv, "s_minimum_days"sv, [](auto minimum_days) { return minimum_days; });
|
||||
append_mapping(locale_data.first_day_regions, locale_data.first_day, "u8"sv, "s_first_day"sv, [](auto first_day) { return to_underlying(first_day); });
|
||||
append_mapping(locale_data.weekend_start_regions, locale_data.weekend_start, "u8"sv, "s_weekend_start"sv, [](auto weekend_start) { return to_underlying(weekend_start); });
|
||||
append_mapping(locale_data.weekend_end_regions, locale_data.weekend_end, "u8"sv, "s_weekend_end"sv, [](auto weekend_end) { return to_underlying(weekend_end); });
|
||||
generate_mapping(generator, cldr.locales, s_calendar_index_type, "s_locale_calendars"sv, "s_calendars_{}"sv, format_identifier, [&](auto const& name, auto const& value) { append_calendars(name, value.calendars); });
|
||||
append_mapping(locales, cldr.locales, s_time_zone_index_type, "s_locale_time_zones"sv, [](auto const& locale) { return locale.time_zones; });
|
||||
append_mapping(locales, cldr.locales, s_time_zone_format_index_type, "s_locale_time_zone_formats"sv, [](auto const& locale) { return locale.time_zone_formats; });
|
||||
append_mapping(locales, cldr.locales, s_day_period_index_type, "s_locale_day_periods"sv, [](auto const& locale) { return locale.day_periods; });
|
||||
append_mapping(cldr.hour_cycle_regions, cldr.hour_cycles, s_hour_cycle_list_index_type, "s_hour_cycles"sv, [](auto const& hour_cycles) { return hour_cycles; });
|
||||
append_mapping(cldr.minimum_days_regions, cldr.minimum_days, "u8"sv, "s_minimum_days"sv, [](auto minimum_days) { return minimum_days; });
|
||||
append_mapping(cldr.first_day_regions, cldr.first_day, "u8"sv, "s_first_day"sv, [](auto first_day) { return to_underlying(first_day); });
|
||||
append_mapping(cldr.weekend_start_regions, cldr.weekend_start, "u8"sv, "s_weekend_start"sv, [](auto weekend_start) { return to_underlying(weekend_start); });
|
||||
append_mapping(cldr.weekend_end_regions, cldr.weekend_end, "u8"sv, "s_weekend_end"sv, [](auto weekend_end) { return to_underlying(weekend_end); });
|
||||
generator.append("\n");
|
||||
|
||||
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) {
|
||||
@ -2034,18 +2034,18 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
|
||||
};
|
||||
|
||||
append_from_string("HourCycleRegion"sv, "hour_cycle_region"sv, locale_data.hour_cycle_regions);
|
||||
append_from_string("MinimumDaysRegion"sv, "minimum_days_region"sv, locale_data.minimum_days_regions);
|
||||
append_from_string("FirstDayRegion"sv, "first_day_region"sv, locale_data.first_day_regions);
|
||||
append_from_string("WeekendStartRegion"sv, "weekend_start_region"sv, locale_data.weekend_start_regions);
|
||||
append_from_string("WeekendEndRegion"sv, "weekend_end_region"sv, locale_data.weekend_end_regions);
|
||||
append_from_string("HourCycleRegion"sv, "hour_cycle_region"sv, cldr.hour_cycle_regions);
|
||||
append_from_string("MinimumDaysRegion"sv, "minimum_days_region"sv, cldr.minimum_days_regions);
|
||||
append_from_string("FirstDayRegion"sv, "first_day_region"sv, cldr.first_day_regions);
|
||||
append_from_string("WeekendStartRegion"sv, "weekend_start_region"sv, cldr.weekend_start_regions);
|
||||
append_from_string("WeekendEndRegion"sv, "weekend_end_region"sv, cldr.weekend_end_regions);
|
||||
|
||||
generator.append(R"~~~(
|
||||
static Optional<Calendar> keyword_to_calendar(KeywordCalendar keyword)
|
||||
{
|
||||
switch (keyword) {)~~~");
|
||||
|
||||
for (auto const& calendar : locale_data.calendars) {
|
||||
for (auto const& calendar : cldr.calendars) {
|
||||
generator.set("name"sv, format_identifier({}, calendar));
|
||||
generator.append(R"~~~(
|
||||
case KeywordCalendar::@name@:
|
||||
@ -2430,11 +2430,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto generated_header_file = TRY(open_file(generated_header_path, Core::Stream::OpenMode::Write));
|
||||
auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::Stream::OpenMode::Write));
|
||||
|
||||
UnicodeLocaleData locale_data;
|
||||
TRY(parse_all_locales(core_path, dates_path, locale_data));
|
||||
CLDR cldr;
|
||||
TRY(parse_all_locales(core_path, dates_path, cldr));
|
||||
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, locale_data));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, locale_data));
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, cldr));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, cldr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -236,13 +236,13 @@ struct AK::Traits<Unit> : public GenericTraits<Unit> {
|
||||
static unsigned hash(Unit const& u) { return u.hash(); }
|
||||
};
|
||||
|
||||
struct Locale {
|
||||
struct LocaleData {
|
||||
Vector<NumberSystemIndexType> number_systems;
|
||||
HashMap<String, UnitIndexType> units {};
|
||||
u8 minimum_grouping_digits { 0 };
|
||||
};
|
||||
|
||||
struct UnicodeLocaleData {
|
||||
struct CLDR {
|
||||
UniqueStringStorage<StringIndexType> unique_strings;
|
||||
UniqueStorage<NumberFormat, NumberFormatIndexType> unique_formats;
|
||||
UniqueStorage<NumberFormatList, NumberFormatListIndexType> unique_format_lists;
|
||||
@ -253,11 +253,11 @@ struct UnicodeLocaleData {
|
||||
HashMap<String, Array<u32, 10>> number_system_digits;
|
||||
Vector<String> number_systems;
|
||||
|
||||
HashMap<String, Locale> locales;
|
||||
HashMap<String, LocaleData> locales;
|
||||
size_t max_identifier_count { 0 };
|
||||
};
|
||||
|
||||
static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, CLDR& cldr)
|
||||
{
|
||||
LexicalPath number_systems_path(move(core_supplemental_path));
|
||||
number_systems_path = number_systems_path.append("numberingSystems.json"sv);
|
||||
@ -276,20 +276,20 @@ static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, U
|
||||
Utf8View utf8_digits { digits };
|
||||
VERIFY(utf8_digits.length() == 10);
|
||||
|
||||
auto& number_system_digits = locale_data.number_system_digits.ensure(number_system);
|
||||
auto& number_system_digits = cldr.number_system_digits.ensure(number_system);
|
||||
size_t index = 0;
|
||||
|
||||
for (u32 digit : utf8_digits)
|
||||
number_system_digits[index++] = digit;
|
||||
|
||||
if (!locale_data.number_systems.contains_slow(number_system))
|
||||
locale_data.number_systems.append(number_system);
|
||||
if (!cldr.number_systems.contains_slow(number_system))
|
||||
cldr.number_systems.append(number_system);
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static String parse_identifiers(String pattern, StringView replacement, UnicodeLocaleData& locale_data, NumberFormat& format)
|
||||
static String parse_identifiers(String pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
|
||||
{
|
||||
static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
|
||||
|
||||
@ -323,7 +323,7 @@ static String parse_identifiers(String pattern, StringView replacement, UnicodeL
|
||||
utf8_pattern = utf8_pattern.trim(whitespace);
|
||||
|
||||
auto identifier = utf8_pattern.as_string().replace("'.'"sv, "."sv, ReplaceMode::FirstOnly);
|
||||
auto identifier_index = locale_data.unique_strings.ensure(move(identifier));
|
||||
auto identifier_index = cldr.unique_strings.ensure(move(identifier));
|
||||
size_t replacement_index = 0;
|
||||
|
||||
if (auto index = format.identifier_indices.find_first_index(identifier_index); index.has_value()) {
|
||||
@ -332,7 +332,7 @@ static String parse_identifiers(String pattern, StringView replacement, UnicodeL
|
||||
replacement_index = format.identifier_indices.size();
|
||||
format.identifier_indices.append(identifier_index);
|
||||
|
||||
locale_data.max_identifier_count = max(locale_data.max_identifier_count, format.identifier_indices.size());
|
||||
cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
|
||||
}
|
||||
|
||||
pattern = String::formatted("{}{{{}:{}}}{}",
|
||||
@ -343,7 +343,7 @@ static String parse_identifiers(String pattern, StringView replacement, UnicodeL
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& locale_data, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
|
||||
static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
|
||||
{
|
||||
// https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
|
||||
// https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
|
||||
@ -401,33 +401,33 @@ static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& loc
|
||||
}
|
||||
|
||||
if (type == NumberFormatType::Compact)
|
||||
return parse_identifiers(move(pattern), "compactIdentifier"sv, locale_data, format);
|
||||
return parse_identifiers(move(pattern), "compactIdentifier"sv, cldr, format);
|
||||
|
||||
return pattern;
|
||||
};
|
||||
|
||||
auto zero_format = replace_patterns(move(patterns[0]));
|
||||
format.positive_format_index = locale_data.unique_strings.ensure(String::formatted("{{plusSign}}{}", zero_format));
|
||||
format.positive_format_index = cldr.unique_strings.ensure(String::formatted("{{plusSign}}{}", zero_format));
|
||||
|
||||
if (patterns.size() == 2) {
|
||||
auto negative_format = replace_patterns(move(patterns[1]));
|
||||
format.negative_format_index = locale_data.unique_strings.ensure(move(negative_format));
|
||||
format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
|
||||
} else {
|
||||
format.negative_format_index = locale_data.unique_strings.ensure(String::formatted("{{minusSign}}{}", zero_format));
|
||||
format.negative_format_index = cldr.unique_strings.ensure(String::formatted("{{minusSign}}{}", zero_format));
|
||||
}
|
||||
|
||||
format.zero_format_index = locale_data.unique_strings.ensure(move(zero_format));
|
||||
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
|
||||
}
|
||||
|
||||
static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& locale_data, NumberFormatType type, NumberFormatIndexType& format_index, NumberSystem* number_system_for_groupings = nullptr)
|
||||
static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberFormatType type, NumberFormatIndexType& format_index, NumberSystem* number_system_for_groupings = nullptr)
|
||||
{
|
||||
NumberFormat format {};
|
||||
parse_number_pattern(move(patterns), locale_data, type, format, number_system_for_groupings);
|
||||
parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
|
||||
|
||||
format_index = locale_data.unique_formats.ensure(move(format));
|
||||
format_index = cldr.unique_formats.ensure(move(format));
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLocaleData& locale_data, Locale& locale)
|
||||
static ErrorOr<void> parse_number_systems(String locale_numbers_path, CLDR& cldr, LocaleData& locale)
|
||||
{
|
||||
LexicalPath numbers_path(move(locale_numbers_path));
|
||||
numbers_path = numbers_path.append("numbers.json"sv);
|
||||
@ -439,10 +439,10 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
auto const& minimum_grouping_digits = locale_numbers_object.as_object().get("minimumGroupingDigits"sv);
|
||||
|
||||
Vector<Optional<NumberSystem>> number_systems;
|
||||
number_systems.resize(locale_data.number_systems.size());
|
||||
number_systems.resize(cldr.number_systems.size());
|
||||
|
||||
auto ensure_number_system = [&](auto const& system) -> NumberSystem& {
|
||||
auto system_index = locale_data.number_systems.find_first_index(system).value();
|
||||
auto system_index = cldr.number_systems.find_first_index(system).value();
|
||||
VERIFY(system_index < number_systems.size());
|
||||
|
||||
auto& number_system = number_systems.at(system_index);
|
||||
@ -479,13 +479,13 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
}
|
||||
|
||||
format.plurality = Unicode::plural_category_from_string(split_key[2]);
|
||||
parse_number_pattern(move(patterns), locale_data, NumberFormatType::Compact, format);
|
||||
parse_number_pattern(move(patterns), cldr, NumberFormatType::Compact, format);
|
||||
|
||||
auto format_index = locale_data.unique_formats.ensure(move(format));
|
||||
auto format_index = cldr.unique_formats.ensure(move(format));
|
||||
result.append(format_index);
|
||||
});
|
||||
|
||||
return locale_data.unique_format_lists.ensure(move(result));
|
||||
return cldr.unique_format_lists.ensure(move(result));
|
||||
};
|
||||
|
||||
auto numeric_symbol_from_string = [&](StringView numeric_symbol) -> Optional<Unicode::NumericSymbol> {
|
||||
@ -534,7 +534,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
if (to_underlying(*numeric_symbol) >= symbols.size())
|
||||
symbols.resize(to_underlying(*numeric_symbol) + 1);
|
||||
|
||||
auto symbol_index = locale_data.unique_strings.ensure(localization.as_string());
|
||||
auto symbol_index = cldr.unique_strings.ensure(localization.as_string());
|
||||
symbols[to_underlying(*numeric_symbol)] = symbol_index;
|
||||
});
|
||||
|
||||
@ -551,16 +551,16 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
if (to_underlying(Unicode::NumericSymbol::RangeSeparator) >= symbols.size())
|
||||
symbols.resize(to_underlying(Unicode::NumericSymbol::RangeSeparator) + 1);
|
||||
|
||||
auto symbol_index = locale_data.unique_strings.ensure(move(range_separator));
|
||||
auto symbol_index = cldr.unique_strings.ensure(move(range_separator));
|
||||
symbols[to_underlying(Unicode::NumericSymbol::RangeSeparator)] = symbol_index;
|
||||
|
||||
number_system.symbols = locale_data.unique_symbols.ensure(move(symbols));
|
||||
number_system.symbols = cldr.unique_symbols.ensure(move(symbols));
|
||||
} else if (key.starts_with(decimal_formats_prefix)) {
|
||||
auto system = key.substring(decimal_formats_prefix.length());
|
||||
auto& number_system = ensure_number_system(system);
|
||||
|
||||
auto format_object = value.as_object().get("standard"sv);
|
||||
parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.decimal_format, &number_system);
|
||||
parse_number_pattern(format_object.as_string().split(';'), cldr, NumberFormatType::Standard, number_system.decimal_format, &number_system);
|
||||
|
||||
auto const& long_format = value.as_object().get("long"sv).as_object().get("decimalFormat"sv);
|
||||
number_system.decimal_long_formats = parse_number_format(long_format.as_object());
|
||||
@ -572,10 +572,10 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
auto& number_system = ensure_number_system(system);
|
||||
|
||||
auto format_object = value.as_object().get("standard"sv);
|
||||
parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.currency_format);
|
||||
parse_number_pattern(format_object.as_string().split(';'), cldr, NumberFormatType::Standard, number_system.currency_format);
|
||||
|
||||
format_object = value.as_object().get("accounting"sv);
|
||||
parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.accounting_format);
|
||||
parse_number_pattern(format_object.as_string().split(';'), cldr, NumberFormatType::Standard, number_system.accounting_format);
|
||||
|
||||
number_system.currency_unit_formats = parse_number_format(value.as_object());
|
||||
|
||||
@ -588,13 +588,13 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
auto& number_system = ensure_number_system(system);
|
||||
|
||||
auto format_object = value.as_object().get("standard"sv);
|
||||
parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.percent_format);
|
||||
parse_number_pattern(format_object.as_string().split(';'), cldr, NumberFormatType::Standard, number_system.percent_format);
|
||||
} else if (key.starts_with(scientific_formats_prefix)) {
|
||||
auto system = key.substring(scientific_formats_prefix.length());
|
||||
auto& number_system = ensure_number_system(system);
|
||||
|
||||
auto format_object = value.as_object().get("standard"sv);
|
||||
parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.scientific_format);
|
||||
parse_number_pattern(format_object.as_string().split(';'), cldr, NumberFormatType::Standard, number_system.scientific_format);
|
||||
}
|
||||
});
|
||||
|
||||
@ -603,7 +603,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
for (auto& number_system : number_systems) {
|
||||
NumberSystemIndexType system_index = 0;
|
||||
if (number_system.has_value())
|
||||
system_index = locale_data.unique_systems.ensure(number_system.release_value());
|
||||
system_index = cldr.unique_systems.ensure(number_system.release_value());
|
||||
|
||||
locale.number_systems.append(system_index);
|
||||
}
|
||||
@ -612,7 +612,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLoc
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& locale_data, Locale& locale)
|
||||
static ErrorOr<void> parse_units(String locale_units_path, CLDR& cldr, LocaleData& locale)
|
||||
{
|
||||
LexicalPath units_path(move(locale_units_path));
|
||||
units_path = units_path.append("units.json"sv);
|
||||
@ -629,7 +629,7 @@ static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& lo
|
||||
|
||||
auto ensure_unit = [&](auto const& unit) -> Unit& {
|
||||
return units.ensure(unit, [&]() {
|
||||
auto unit_index = locale_data.unique_strings.ensure(unit);
|
||||
auto unit_index = cldr.unique_strings.ensure(unit);
|
||||
return Unit { .unit = unit_index };
|
||||
});
|
||||
};
|
||||
@ -679,16 +679,16 @@ static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& lo
|
||||
format.plurality = Unicode::plural_category_from_string(plurality);
|
||||
|
||||
auto zero_format = pattern_value.as_string().replace("{0}"sv, "{number}"sv, ReplaceMode::FirstOnly);
|
||||
zero_format = parse_identifiers(zero_format, "unitIdentifier"sv, locale_data, format);
|
||||
zero_format = parse_identifiers(zero_format, "unitIdentifier"sv, cldr, format);
|
||||
|
||||
format.positive_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.negative_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.zero_format_index = locale_data.unique_strings.ensure(move(zero_format));
|
||||
format.positive_format_index = cldr.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.negative_format_index = cldr.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
|
||||
|
||||
formats.append(locale_data.unique_formats.ensure(move(format)));
|
||||
formats.append(cldr.unique_formats.ensure(move(format)));
|
||||
});
|
||||
|
||||
auto number_format_list_index = locale_data.unique_format_lists.ensure(move(formats));
|
||||
auto number_format_list_index = cldr.unique_format_lists.ensure(move(formats));
|
||||
|
||||
switch (style) {
|
||||
case Unicode::Style::Long:
|
||||
@ -711,14 +711,14 @@ static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& lo
|
||||
parse_units_object(narrow_object.as_object(), Unicode::Style::Narrow);
|
||||
|
||||
for (auto& unit : units) {
|
||||
auto unit_index = locale_data.unique_units.ensure(move(unit.value));
|
||||
auto unit_index = cldr.unique_units.ensure(move(unit.value));
|
||||
locale.units.set(unit.key, unit_index);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, String units_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, String units_path, CLDR& cldr)
|
||||
{
|
||||
auto numbers_iterator = TRY(path_to_dir_iterator(move(numbers_path)));
|
||||
auto units_iterator = TRY(path_to_dir_iterator(move(units_path)));
|
||||
@ -727,16 +727,16 @@ static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, St
|
||||
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
||||
VERIFY(Core::File::is_directory(core_supplemental_path.string()));
|
||||
|
||||
TRY(parse_number_system_digits(core_supplemental_path.string(), locale_data));
|
||||
TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
|
||||
|
||||
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(locale_data.unique_strings, LexicalPath::basename(path)));
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(locale_data.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = locale_data.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.append(cldr.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = cldr.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.appendff("-{}", script);
|
||||
if (auto region = locale_data.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
builder.appendff("-{}", region);
|
||||
|
||||
return builder.build();
|
||||
@ -746,16 +746,16 @@ static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, St
|
||||
auto numbers_path = TRY(next_path_from_dir_iterator(numbers_iterator));
|
||||
auto language = TRY(remove_variants_from_path(numbers_path));
|
||||
|
||||
auto& locale = locale_data.locales.ensure(language);
|
||||
TRY(parse_number_systems(numbers_path, locale_data, locale));
|
||||
auto& locale = cldr.locales.ensure(language);
|
||||
TRY(parse_number_systems(numbers_path, cldr, locale));
|
||||
}
|
||||
|
||||
while (units_iterator.has_next()) {
|
||||
auto units_path = TRY(next_path_from_dir_iterator(units_iterator));
|
||||
auto language = TRY(remove_variants_from_path(units_path));
|
||||
|
||||
auto& locale = locale_data.locales.ensure(language);
|
||||
TRY(parse_units(units_path, locale_data, locale));
|
||||
auto& locale = cldr.locales.ensure(language);
|
||||
TRY(parse_units(units_path, cldr, locale));
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -766,7 +766,7 @@ static String format_identifier(StringView, String identifier)
|
||||
return identifier.to_titlecase();
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -779,7 +779,7 @@ static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile&
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
generate_enum(generator, format_identifier, "NumberSystem"sv, {}, locale_data.number_systems);
|
||||
generate_enum(generator, format_identifier, "NumberSystem"sv, {}, cldr.number_systems);
|
||||
|
||||
generator.append(R"~~~(
|
||||
}
|
||||
@ -789,7 +789,7 @@ namespace Unicode {
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -797,7 +797,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
|
||||
generator.set("number_format_index_type"sv, s_number_format_index_type);
|
||||
generator.set("number_format_list_index_type"sv, s_number_format_list_index_type);
|
||||
generator.set("numeric_symbol_list_index_type"sv, s_numeric_symbol_list_index_type);
|
||||
generator.set("identifier_count", String::number(locale_data.max_identifier_count));
|
||||
generator.set("identifier_count", String::number(cldr.max_identifier_count));
|
||||
|
||||
generator.append(R"~~~(
|
||||
#include <AK/Array.h>
|
||||
@ -815,7 +815,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_strings.generate(generator);
|
||||
cldr.unique_strings.generate(generator);
|
||||
|
||||
generator.append(R"~~~(
|
||||
struct NumberFormatImpl {
|
||||
@ -872,13 +872,13 @@ struct Unit {
|
||||
};
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_formats.generate(generator, "NumberFormatImpl"sv, "s_number_formats"sv, 10);
|
||||
locale_data.unique_format_lists.generate(generator, s_number_format_index_type, "s_number_format_lists"sv);
|
||||
locale_data.unique_symbols.generate(generator, s_string_index_type, "s_numeric_symbol_lists"sv);
|
||||
locale_data.unique_systems.generate(generator, "NumberSystemData"sv, "s_number_systems"sv, 10);
|
||||
locale_data.unique_units.generate(generator, "Unit"sv, "s_units"sv, 10);
|
||||
cldr.unique_formats.generate(generator, "NumberFormatImpl"sv, "s_number_formats"sv, 10);
|
||||
cldr.unique_format_lists.generate(generator, s_number_format_index_type, "s_number_format_lists"sv);
|
||||
cldr.unique_symbols.generate(generator, s_string_index_type, "s_numeric_symbol_lists"sv);
|
||||
cldr.unique_systems.generate(generator, "NumberSystemData"sv, "s_number_systems"sv, 10);
|
||||
cldr.unique_units.generate(generator, "Unit"sv, "s_units"sv, 10);
|
||||
|
||||
auto locales = locale_data.locales.keys();
|
||||
auto locales = cldr.locales.keys();
|
||||
quick_sort(locales);
|
||||
|
||||
generator.set("size", String::number(locales.size()));
|
||||
@ -888,7 +888,7 @@ static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
|
||||
bool first = true;
|
||||
for (auto const& locale : locales) {
|
||||
generator.append(first ? " "sv : ", "sv);
|
||||
generator.append(String::number(locale_data.locales.find(locale)->value.minimum_grouping_digits));
|
||||
generator.append(String::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
|
||||
first = false;
|
||||
}
|
||||
generator.append(" } };\n");
|
||||
@ -914,16 +914,16 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||
generator.append(" } };");
|
||||
};
|
||||
|
||||
generate_mapping(generator, locale_data.number_system_digits, "u32"sv, "s_number_systems_digits"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, "u32"sv, value); });
|
||||
generate_mapping(generator, locale_data.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
|
||||
generate_mapping(generator, locale_data.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
|
||||
generate_mapping(generator, cldr.number_system_digits, "u32"sv, "s_number_systems_digits"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, "u32"sv, value); });
|
||||
generate_mapping(generator, cldr.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
|
||||
generate_mapping(generator, cldr.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
|
||||
|
||||
generator.append(R"~~~(
|
||||
static Optional<NumberSystem> keyword_to_number_system(KeywordNumbers keyword)
|
||||
{
|
||||
switch (keyword) {)~~~");
|
||||
|
||||
for (auto const& number_system : locale_data.number_systems) {
|
||||
for (auto const& number_system : cldr.number_systems) {
|
||||
generator.set("name"sv, format_identifier({}, number_system));
|
||||
generator.append(R"~~~(
|
||||
case KeywordNumbers::@name@:
|
||||
@ -1152,11 +1152,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto generated_header_file = TRY(open_file(generated_header_path, Core::Stream::OpenMode::Write));
|
||||
auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::Stream::OpenMode::Write));
|
||||
|
||||
UnicodeLocaleData locale_data;
|
||||
TRY(parse_all_locales(core_path, numbers_path, units_path, locale_data));
|
||||
CLDR cldr;
|
||||
TRY(parse_all_locales(core_path, numbers_path, units_path, cldr));
|
||||
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, locale_data));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, locale_data));
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, cldr));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, cldr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ struct Range {
|
||||
using Conditions = HashMap<String, Condition>;
|
||||
using Ranges = Vector<Range>;
|
||||
|
||||
struct Locale {
|
||||
struct LocaleData {
|
||||
static String generated_method_name(StringView form, StringView locale)
|
||||
{
|
||||
return String::formatted("{}_plurality_{}", form, format_identifier({}, locale));
|
||||
@ -213,10 +213,10 @@ struct Locale {
|
||||
Ranges plural_ranges;
|
||||
};
|
||||
|
||||
struct UnicodeLocaleData {
|
||||
struct CLDR {
|
||||
UniqueStringStorage<StringIndexType> unique_strings;
|
||||
|
||||
HashMap<String, Locale> locales;
|
||||
HashMap<String, LocaleData> locales;
|
||||
};
|
||||
|
||||
static Relation parse_relation(StringView relation)
|
||||
@ -324,7 +324,7 @@ static void parse_condition(StringView category, StringView rule, Conditions& ru
|
||||
});
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringView file_name, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringView file_name, CLDR& cldr)
|
||||
{
|
||||
static constexpr auto form_prefix = "plurals-type-"sv;
|
||||
static constexpr auto rule_prefix = "pluralRule-count-"sv;
|
||||
@ -342,7 +342,7 @@ static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringVie
|
||||
auto form = key.substring_view(form_prefix.length());
|
||||
|
||||
plurals_object.as_object().for_each_member([&](auto const& loc, auto const& rules) {
|
||||
auto locale = locale_data.locales.get(loc);
|
||||
auto locale = cldr.locales.get(loc);
|
||||
if (!locale.has_value())
|
||||
return;
|
||||
|
||||
@ -359,7 +359,7 @@ static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringVie
|
||||
}
|
||||
|
||||
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges
|
||||
static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, CLDR& cldr)
|
||||
{
|
||||
static constexpr auto start_segment = "-start-"sv;
|
||||
static constexpr auto end_segment = "-end-"sv;
|
||||
@ -372,7 +372,7 @@ static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, UnicodeL
|
||||
auto const& plurals_object = supplemental_object.as_object().get("plurals"sv);
|
||||
|
||||
plurals_object.as_object().for_each_member([&](auto const& loc, auto const& ranges_object) {
|
||||
auto locale = locale_data.locales.get(loc);
|
||||
auto locale = cldr.locales.get(loc);
|
||||
if (!locale.has_value())
|
||||
return;
|
||||
|
||||
@ -395,7 +395,7 @@ static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, UnicodeL
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String locale_names_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_all_locales(String core_path, String locale_names_path, CLDR& cldr)
|
||||
{
|
||||
auto identity_iterator = TRY(path_to_dir_iterator(move(locale_names_path)));
|
||||
|
||||
@ -404,13 +404,13 @@ static ErrorOr<void> parse_all_locales(String core_path, String locale_names_pat
|
||||
VERIFY(Core::File::is_directory(core_supplemental_path.string()));
|
||||
|
||||
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(locale_data.unique_strings, LexicalPath::basename(path)));
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(locale_data.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = locale_data.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.append(cldr.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = cldr.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.appendff("-{}", script);
|
||||
if (auto region = locale_data.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
builder.appendff("-{}", region);
|
||||
|
||||
return builder.build();
|
||||
@ -420,16 +420,16 @@ static ErrorOr<void> parse_all_locales(String core_path, String locale_names_pat
|
||||
auto locale_path = TRY(next_path_from_dir_iterator(identity_iterator));
|
||||
auto language = TRY(remove_variants_from_path(locale_path));
|
||||
|
||||
locale_data.locales.ensure(language);
|
||||
cldr.locales.ensure(language);
|
||||
}
|
||||
|
||||
TRY(parse_plural_rules(core_supplemental_path.string(), "plurals.json"sv, locale_data));
|
||||
TRY(parse_plural_rules(core_supplemental_path.string(), "ordinals.json"sv, locale_data));
|
||||
TRY(parse_plural_ranges(core_supplemental_path.string(), locale_data));
|
||||
TRY(parse_plural_rules(core_supplemental_path.string(), "plurals.json"sv, cldr));
|
||||
TRY(parse_plural_rules(core_supplemental_path.string(), "ordinals.json"sv, cldr));
|
||||
TRY(parse_plural_ranges(core_supplemental_path.string(), cldr));
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData&)
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, CLDR&)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -450,12 +450,12 @@ namespace Unicode {
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
|
||||
auto locales = locale_data.locales.keys();
|
||||
auto locales = cldr.locales.keys();
|
||||
quick_sort(locales);
|
||||
|
||||
generator.append(R"~~~(
|
||||
@ -487,7 +487,7 @@ static PluralCategory default_range(PluralCategory, PluralCategory end)
|
||||
if (rules.is_empty())
|
||||
return;
|
||||
|
||||
generator.set("method"sv, Locale::generated_method_name(form, locale));
|
||||
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
|
||||
HashTable<String> generated_variables;
|
||||
|
||||
generator.append(R"~~~(
|
||||
@ -517,7 +517,7 @@ static PluralCategory @method@([[maybe_unused]] PluralOperands ops)
|
||||
if (ranges.is_empty())
|
||||
return;
|
||||
|
||||
generator.set("method"sv, Locale::generated_method_name("range"sv, locale));
|
||||
generator.set("method"sv, LocaleData::generated_method_name("range"sv, locale));
|
||||
|
||||
generator.append(R"~~~(
|
||||
static PluralCategory @method@(PluralCategory start, PluralCategory end)
|
||||
@ -549,13 +549,13 @@ static PluralCategory @method@(PluralCategory start, PluralCategory end)
|
||||
static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
|
||||
|
||||
for (auto const& locale : locales) {
|
||||
auto& rules = data_for_locale(locale_data.locales.find(locale)->value, form);
|
||||
auto& rules = data_for_locale(cldr.locales.find(locale)->value, form);
|
||||
|
||||
if (rules.is_empty()) {
|
||||
generator.append(R"~~~(
|
||||
@default@,)~~~");
|
||||
} else {
|
||||
generator.set("method"sv, Locale::generated_method_name(form, locale));
|
||||
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
|
||||
generator.append(R"~~~(
|
||||
@method@,)~~~");
|
||||
}
|
||||
@ -581,7 +581,7 @@ static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)
|
||||
generator.append("} };");
|
||||
};
|
||||
|
||||
for (auto [locale, rules] : locale_data.locales) {
|
||||
for (auto [locale, rules] : cldr.locales) {
|
||||
append_rules("cardinal"sv, locale, rules.cardinal_rules);
|
||||
append_rules("ordinal"sv, locale, rules.ordinal_rules);
|
||||
append_ranges(locale, rules.plural_ranges);
|
||||
@ -593,13 +593,13 @@ static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)
|
||||
|
||||
generate_mapping(generator, locales, "PluralCategory"sv, "s_cardinal_categories"sv, "s_cardinal_categories_{}"sv, format_identifier,
|
||||
[&](auto const& name, auto const& locale) {
|
||||
auto& rules = locale_data.locales.find(locale)->value;
|
||||
auto& rules = cldr.locales.find(locale)->value;
|
||||
append_categories(name, rules.rules_for_form("cardinal"sv));
|
||||
});
|
||||
|
||||
generate_mapping(generator, locales, "PluralCategory"sv, "s_ordinal_categories"sv, "s_ordinal_categories_{}"sv, format_identifier,
|
||||
[&](auto const& name, auto const& locale) {
|
||||
auto& rules = locale_data.locales.find(locale)->value;
|
||||
auto& rules = cldr.locales.find(locale)->value;
|
||||
append_categories(name, rules.rules_for_form("ordinal"sv));
|
||||
});
|
||||
|
||||
@ -679,11 +679,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto generated_header_file = TRY(open_file(generated_header_path, Core::Stream::OpenMode::Write));
|
||||
auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::Stream::OpenMode::Write));
|
||||
|
||||
UnicodeLocaleData locale_data;
|
||||
TRY(parse_all_locales(core_path, locale_names_path, locale_data));
|
||||
CLDR cldr;
|
||||
TRY(parse_all_locales(core_path, locale_names_path, cldr));
|
||||
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, locale_data));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, locale_data));
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, cldr));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, cldr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -72,18 +72,18 @@ struct AK::Traits<RelativeTimeFormat> : public GenericTraits<RelativeTimeFormat>
|
||||
static unsigned hash(RelativeTimeFormat const& format) { return format.hash(); }
|
||||
};
|
||||
|
||||
struct Locale {
|
||||
struct LocaleData {
|
||||
Vector<RelativeTimeFormatIndexType> time_units;
|
||||
};
|
||||
|
||||
struct UnicodeLocaleData {
|
||||
struct CLDR {
|
||||
UniqueStringStorage<StringIndexType> unique_strings;
|
||||
UniqueStorage<RelativeTimeFormat, RelativeTimeFormatIndexType> unique_formats;
|
||||
|
||||
HashMap<String, Locale> locales;
|
||||
HashMap<String, LocaleData> locales;
|
||||
};
|
||||
|
||||
static ErrorOr<void> parse_date_fields(String locale_dates_path, UnicodeLocaleData& locale_data, Locale& locale)
|
||||
static ErrorOr<void> parse_date_fields(String locale_dates_path, CLDR& cldr, LocaleData& locale)
|
||||
{
|
||||
LexicalPath date_fields_path(move(locale_dates_path));
|
||||
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
||||
@ -105,10 +105,10 @@ static ErrorOr<void> parse_date_fields(String locale_dates_path, UnicodeLocaleDa
|
||||
format.time_unit = unit.to_titlecase_string();
|
||||
format.style = style.to_titlecase_string();
|
||||
format.plurality = plurality.to_titlecase_string();
|
||||
format.tense_or_number = locale_data.unique_strings.ensure(tense_or_number);
|
||||
format.pattern = locale_data.unique_strings.ensure(pattern.as_string());
|
||||
format.tense_or_number = cldr.unique_strings.ensure(tense_or_number);
|
||||
format.pattern = cldr.unique_strings.ensure(pattern.as_string());
|
||||
|
||||
locale.time_units.append(locale_data.unique_formats.ensure(move(format)));
|
||||
locale.time_units.append(cldr.unique_formats.ensure(move(format)));
|
||||
};
|
||||
|
||||
fields_object.as_object().for_each_member([&](auto const& unit_and_style, auto const& patterns) {
|
||||
@ -142,18 +142,18 @@ static ErrorOr<void> parse_date_fields(String locale_dates_path, UnicodeLocaleDa
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_all_locales(String dates_path, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> parse_all_locales(String dates_path, CLDR& cldr)
|
||||
{
|
||||
auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
|
||||
|
||||
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(locale_data.unique_strings, LexicalPath::basename(path)));
|
||||
auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(locale_data.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = locale_data.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.append(cldr.unique_strings.get(parsed_locale.language));
|
||||
if (auto script = cldr.unique_strings.get(parsed_locale.script); !script.is_empty())
|
||||
builder.appendff("-{}", script);
|
||||
if (auto region = locale_data.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||
builder.appendff("-{}", region);
|
||||
|
||||
return builder.build();
|
||||
@ -163,14 +163,14 @@ static ErrorOr<void> parse_all_locales(String dates_path, UnicodeLocaleData& loc
|
||||
auto dates_path = TRY(next_path_from_dir_iterator(dates_iterator));
|
||||
auto language = TRY(remove_variants_from_path(dates_path));
|
||||
|
||||
auto& locale = locale_data.locales.ensure(language);
|
||||
TRY(parse_date_fields(move(dates_path), locale_data, locale));
|
||||
auto& locale = cldr.locales.ensure(language);
|
||||
TRY(parse_date_fields(move(dates_path), cldr, locale));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData&)
|
||||
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, CLDR&)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -191,7 +191,7 @@ namespace Unicode {
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
|
||||
static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, CLDR& cldr)
|
||||
{
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
@ -210,7 +210,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_strings.generate(generator);
|
||||
cldr.unique_strings.generate(generator);
|
||||
|
||||
generator.append(R"~~~(
|
||||
struct RelativeTimeFormatImpl {
|
||||
@ -231,7 +231,7 @@ struct RelativeTimeFormatImpl {
|
||||
};
|
||||
)~~~");
|
||||
|
||||
locale_data.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
|
||||
cldr.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
|
||||
|
||||
auto append_list = [&](String name, auto const& list) {
|
||||
generator.set("name", name);
|
||||
@ -250,7 +250,7 @@ static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~
|
||||
generator.append(" } };");
|
||||
};
|
||||
|
||||
generate_mapping(generator, locale_data.locales, s_relative_time_format_index_type, "s_locale_relative_time_formats"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_list(name, value.time_units); });
|
||||
generate_mapping(generator, cldr.locales, s_relative_time_format_index_type, "s_locale_relative_time_formats"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_list(name, value.time_units); });
|
||||
|
||||
generator.append(R"~~~(
|
||||
Vector<RelativeTimeFormat> get_relative_time_format_patterns(StringView locale, TimeUnit time_unit, StringView tense_or_number, Style style)
|
||||
@ -302,11 +302,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto generated_header_file = TRY(open_file(generated_header_path, Core::Stream::OpenMode::Write));
|
||||
auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::Stream::OpenMode::Write));
|
||||
|
||||
UnicodeLocaleData locale_data;
|
||||
TRY(parse_all_locales(dates_path, locale_data));
|
||||
CLDR cldr;
|
||||
TRY(parse_all_locales(dates_path, cldr));
|
||||
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, locale_data));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, locale_data));
|
||||
TRY(generate_unicode_locale_header(*generated_header_file, cldr));
|
||||
TRY(generate_unicode_locale_implementation(*generated_implementation_file, cldr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user