mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +00:00
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:
parent
87abf00f7c
commit
ca9123f66f
1 changed files with 21 additions and 21 deletions
|
@ -55,10 +55,10 @@ constexpr auto s_calendar_symbols_list_index_type = "u8"sv;
|
||||||
using CalendarIndexType = u8;
|
using CalendarIndexType = u8;
|
||||||
constexpr auto s_calendar_index_type = "u8"sv;
|
constexpr auto s_calendar_index_type = "u8"sv;
|
||||||
|
|
||||||
using TimeZoneIndexType = u16;
|
using TimeZoneNamesIndexType = u16;
|
||||||
constexpr auto s_time_zone_index_type = "u16"sv;
|
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;
|
constexpr auto s_time_zone_list_index_type = "u8"sv;
|
||||||
|
|
||||||
using TimeZoneFormatIndexType = u8;
|
using TimeZoneFormatIndexType = u8;
|
||||||
|
@ -379,13 +379,13 @@ struct AK::Traits<Calendar> : public GenericTraits<Calendar> {
|
||||||
static unsigned hash(Calendar const& c) { return c.hash(); }
|
static unsigned hash(Calendar const& c) { return c.hash(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimeZone {
|
struct TimeZoneNames {
|
||||||
unsigned hash() const
|
unsigned hash() const
|
||||||
{
|
{
|
||||||
return pair_int_hash(long_name, short_name);
|
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);
|
return (long_name == other.long_name) && (short_name == other.short_name);
|
||||||
}
|
}
|
||||||
|
@ -395,8 +395,8 @@ struct TimeZone {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<TimeZone> : Formatter<FormatString> {
|
struct AK::Formatter<TimeZoneNames> : Formatter<FormatString> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, TimeZone const& time_zone)
|
ErrorOr<void> format(FormatBuilder& builder, TimeZoneNames const& time_zone)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(builder,
|
return Formatter<FormatString>::format(builder,
|
||||||
"{{ {}, {} }}",
|
"{{ {}, {} }}",
|
||||||
|
@ -406,8 +406,8 @@ struct AK::Formatter<TimeZone> : Formatter<FormatString> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Traits<TimeZone> : public GenericTraits<TimeZone> {
|
struct AK::Traits<TimeZoneNames> : public GenericTraits<TimeZoneNames> {
|
||||||
static unsigned hash(TimeZone const& t) { return t.hash(); }
|
static unsigned hash(TimeZoneNames const& t) { return t.hash(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimeZoneFormat {
|
struct TimeZoneFormat {
|
||||||
|
@ -475,7 +475,7 @@ struct AK::Traits<DayPeriod> : public GenericTraits<DayPeriod> {
|
||||||
static unsigned hash(DayPeriod const& d) { return d.hash(); }
|
static unsigned hash(DayPeriod const& d) { return d.hash(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
using TimeZoneList = Vector<TimeZoneIndexType>;
|
using TimeZoneNamesList = Vector<TimeZoneNamesIndexType>;
|
||||||
using DayPeriodList = Vector<DayPeriodIndexType>;
|
using DayPeriodList = Vector<DayPeriodIndexType>;
|
||||||
using HourCycleList = Vector<Unicode::HourCycle>;
|
using HourCycleList = Vector<Unicode::HourCycle>;
|
||||||
|
|
||||||
|
@ -490,7 +490,7 @@ struct AK::Formatter<Unicode::HourCycle> : Formatter<FormatString> {
|
||||||
struct Locale {
|
struct Locale {
|
||||||
HashMap<String, CalendarIndexType> calendars;
|
HashMap<String, CalendarIndexType> calendars;
|
||||||
|
|
||||||
TimeZoneListIndexType time_zones { 0 };
|
TimeZoneNamesListIndexType time_zones { 0 };
|
||||||
TimeZoneFormatIndexType time_zone_formats { 0 };
|
TimeZoneFormatIndexType time_zone_formats { 0 };
|
||||||
|
|
||||||
DayPeriodListIndexType day_periods { 0 };
|
DayPeriodListIndexType day_periods { 0 };
|
||||||
|
@ -507,8 +507,8 @@ struct UnicodeLocaleData {
|
||||||
UniqueStorage<CalendarSymbols, CalendarSymbolsIndexType> unique_calendar_symbols;
|
UniqueStorage<CalendarSymbols, CalendarSymbolsIndexType> unique_calendar_symbols;
|
||||||
UniqueStorage<CalendarSymbolsList, CalendarSymbolsListIndexType> unique_calendar_symbols_lists;
|
UniqueStorage<CalendarSymbolsList, CalendarSymbolsListIndexType> unique_calendar_symbols_lists;
|
||||||
UniqueStorage<Calendar, CalendarIndexType> unique_calendars;
|
UniqueStorage<Calendar, CalendarIndexType> unique_calendars;
|
||||||
UniqueStorage<TimeZone, TimeZoneIndexType> unique_time_zones;
|
UniqueStorage<TimeZoneNames, TimeZoneNamesIndexType> unique_time_zones;
|
||||||
UniqueStorage<TimeZoneList, TimeZoneListIndexType> unique_time_zone_lists;
|
UniqueStorage<TimeZoneNamesList, TimeZoneNamesListIndexType> unique_time_zone_lists;
|
||||||
UniqueStorage<TimeZoneFormat, TimeZoneFormatIndexType> unique_time_zone_formats;
|
UniqueStorage<TimeZoneFormat, TimeZoneFormatIndexType> unique_time_zone_formats;
|
||||||
UniqueStorage<DayPeriod, DayPeriodIndexType> unique_day_periods;
|
UniqueStorage<DayPeriod, DayPeriodIndexType> unique_day_periods;
|
||||||
UniqueStorage<DayPeriodList, DayPeriodListIndexType> unique_day_period_lists;
|
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 {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
TimeZoneList time_zones;
|
TimeZoneNamesList time_zones;
|
||||||
|
|
||||||
TimeZoneFormat time_zone_formats {};
|
TimeZoneFormat time_zone_formats {};
|
||||||
time_zone_formats.gmt_zero_format = locale_data.unique_strings.ensure(gmt_zero_format_string.as_string());
|
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 parse_time_zone = [&](StringView meta_zone, JsonObject const& meta_zone_object) {
|
||||||
auto const& golden_zones = locale_data.meta_zones.find(meta_zone)->value;
|
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())
|
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())
|
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) {
|
for (auto const& golden_zone : golden_zones) {
|
||||||
auto time_zone_index = locale_data.time_zones.find_first_index(golden_zone).value();
|
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 };
|
@calendar_symbols_list_index_type@ symbols { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimeZoneData {
|
struct TimeZoneNames {
|
||||||
@string_index_type@ long_name { 0 };
|
@string_index_type@ long_name { 0 };
|
||||||
@string_index_type@ short_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.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_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_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_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_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);
|
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);
|
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);
|
auto locale_value = locale_from_string(locale);
|
||||||
if (!locale_value.has_value())
|
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)
|
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style)
|
||||||
{
|
{
|
||||||
if ((style == CalendarPatternStyle::Long) || (style == CalendarPatternStyle::Short)) {
|
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;
|
auto time_zone_index = style == CalendarPatternStyle::Long ? data->long_name : data->short_name;
|
||||||
if (time_zone_index != 0)
|
if (time_zone_index != 0)
|
||||||
return s_string_list[time_zone_index];
|
return s_string_list[time_zone_index];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue