LibUnicode: Rename DateTimeFormat's generator's TimeZone struct

Before using LibTimeZone within LibUnicode, rename this structure to
avoid naming conflicts with the TimeZone namespace.
This commit is contained in:
Timothy Flynn 2022-01-07 08:40:04 -05:00 committed by Linus Groh
parent 87abf00f7c
commit ca9123f66f

View file

@ -55,10 +55,10 @@ constexpr auto s_calendar_symbols_list_index_type = "u8"sv;
using CalendarIndexType = u8;
constexpr auto s_calendar_index_type = "u8"sv;
using TimeZoneIndexType = u16;
using TimeZoneNamesIndexType = u16;
constexpr auto s_time_zone_index_type = "u16"sv;
using TimeZoneListIndexType = u8;
using TimeZoneNamesListIndexType = u8;
constexpr auto s_time_zone_list_index_type = "u8"sv;
using TimeZoneFormatIndexType = u8;
@ -379,13 +379,13 @@ struct AK::Traits<Calendar> : public GenericTraits<Calendar> {
static unsigned hash(Calendar const& c) { return c.hash(); }
};
struct TimeZone {
struct TimeZoneNames {
unsigned hash() const
{
return pair_int_hash(long_name, short_name);
}
bool operator==(TimeZone const& other) const
bool operator==(TimeZoneNames const& other) const
{
return (long_name == other.long_name) && (short_name == other.short_name);
}
@ -395,8 +395,8 @@ struct TimeZone {
};
template<>
struct AK::Formatter<TimeZone> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, TimeZone const& time_zone)
struct AK::Formatter<TimeZoneNames> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, TimeZoneNames const& time_zone)
{
return Formatter<FormatString>::format(builder,
"{{ {}, {} }}",
@ -406,8 +406,8 @@ struct AK::Formatter<TimeZone> : Formatter<FormatString> {
};
template<>
struct AK::Traits<TimeZone> : public GenericTraits<TimeZone> {
static unsigned hash(TimeZone const& t) { return t.hash(); }
struct AK::Traits<TimeZoneNames> : public GenericTraits<TimeZoneNames> {
static unsigned hash(TimeZoneNames const& t) { return t.hash(); }
};
struct TimeZoneFormat {
@ -475,7 +475,7 @@ struct AK::Traits<DayPeriod> : public GenericTraits<DayPeriod> {
static unsigned hash(DayPeriod const& d) { return d.hash(); }
};
using TimeZoneList = Vector<TimeZoneIndexType>;
using TimeZoneNamesList = Vector<TimeZoneNamesIndexType>;
using DayPeriodList = Vector<DayPeriodIndexType>;
using HourCycleList = Vector<Unicode::HourCycle>;
@ -490,7 +490,7 @@ struct AK::Formatter<Unicode::HourCycle> : Formatter<FormatString> {
struct Locale {
HashMap<String, CalendarIndexType> calendars;
TimeZoneListIndexType time_zones { 0 };
TimeZoneNamesListIndexType time_zones { 0 };
TimeZoneFormatIndexType time_zone_formats { 0 };
DayPeriodListIndexType day_periods { 0 };
@ -507,8 +507,8 @@ struct UnicodeLocaleData {
UniqueStorage<CalendarSymbols, CalendarSymbolsIndexType> unique_calendar_symbols;
UniqueStorage<CalendarSymbolsList, CalendarSymbolsListIndexType> unique_calendar_symbols_lists;
UniqueStorage<Calendar, CalendarIndexType> unique_calendars;
UniqueStorage<TimeZone, TimeZoneIndexType> unique_time_zones;
UniqueStorage<TimeZoneList, TimeZoneListIndexType> unique_time_zone_lists;
UniqueStorage<TimeZoneNames, TimeZoneNamesIndexType> unique_time_zones;
UniqueStorage<TimeZoneNamesList, TimeZoneNamesListIndexType> unique_time_zone_lists;
UniqueStorage<TimeZoneFormat, TimeZoneFormatIndexType> unique_time_zone_formats;
UniqueStorage<DayPeriod, DayPeriodIndexType> unique_day_periods;
UniqueStorage<DayPeriodList, DayPeriodListIndexType> unique_day_period_lists;
@ -1397,23 +1397,23 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, U
return {};
};
TimeZoneList time_zones;
TimeZoneNamesList time_zones;
TimeZoneFormat time_zone_formats {};
time_zone_formats.gmt_zero_format = locale_data.unique_strings.ensure(gmt_zero_format_string.as_string());
auto parse_time_zone = [&](StringView meta_zone, JsonObject const& meta_zone_object) {
auto const& golden_zones = locale_data.meta_zones.find(meta_zone)->value;
TimeZone time_zone {};
TimeZoneNames time_zone_names {};
if (auto long_name = parse_name("long"sv, meta_zone_object); long_name.has_value())
time_zone.long_name = long_name.value();
time_zone_names.long_name = long_name.value();
if (auto short_name = parse_name("short"sv, meta_zone_object); short_name.has_value())
time_zone.short_name = short_name.value();
time_zone_names.short_name = short_name.value();
for (auto const& golden_zone : golden_zones) {
auto time_zone_index = locale_data.time_zones.find_first_index(golden_zone).value();
time_zones[time_zone_index] = locale_data.unique_time_zones.ensure(move(time_zone));
time_zones[time_zone_index] = locale_data.unique_time_zones.ensure(move(time_zone_names));
}
};
@ -1743,7 +1743,7 @@ struct CalendarData {
@calendar_symbols_list_index_type@ symbols { 0 };
};
struct TimeZoneData {
struct TimeZoneNames {
@string_index_type@ long_name { 0 };
@string_index_type@ short_name { 0 };
};
@ -1764,7 +1764,7 @@ struct DayPeriodData {
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, "TimeZoneData"sv, "s_time_zones"sv, 30);
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, "TimeZoneFormat"sv, "s_time_zone_formats"sv, 30);
locale_data.unique_day_periods.generate(generator, "DayPeriodData"sv, "s_day_periods"sv, 30);
@ -2081,7 +2081,7 @@ static TimeZoneFormat const* find_time_zone_formats(StringView locale)
return &s_time_zone_formats.at(time_zone_format_index);
}
static TimeZoneData const* find_time_zone_data(StringView locale, StringView time_zone)
static TimeZoneNames const* find_time_zone_names(StringView locale, StringView time_zone)
{
auto locale_value = locale_from_string(locale);
if (!locale_value.has_value())
@ -2104,7 +2104,7 @@ static TimeZoneData const* find_time_zone_data(StringView locale, StringView tim
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style)
{
if ((style == CalendarPatternStyle::Long) || (style == CalendarPatternStyle::Short)) {
if (auto const* data = find_time_zone_data(locale, time_zone); data != nullptr) {
if (auto const* data = find_time_zone_names(locale, time_zone); data != nullptr) {
auto time_zone_index = style == CalendarPatternStyle::Long ? data->long_name : data->short_name;
if (time_zone_index != 0)
return s_string_list[time_zone_index];