diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index a1ca20e203..90004cc046 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -1500,9 +1500,7 @@ static void generate_unicode_locale_header(Core::File& file, UnicodeLocaleData& generator.append(R"~~~( #pragma once -#include -#include -#include +#include namespace Unicode { )~~~"); @@ -1512,33 +1510,6 @@ namespace Unicode { generate_enum(generator, format_identifier, "TimeZone"sv, {}, locale_data.time_zones); generator.append(R"~~~( -namespace Detail { - -Optional calendar_from_string(StringView calendar); - -Optional hour_cycle_region_from_string(StringView hour_cycle_region); -Vector get_regional_hour_cycles(StringView region); - -Optional get_calendar_date_format(StringView locale, StringView calendar); -Optional get_calendar_time_format(StringView locale, StringView calendar); -Optional get_calendar_date_time_format(StringView locale, StringView calendar); -Vector get_calendar_available_formats(StringView locale, StringView calendar); - -Optional get_calendar_default_range_format(StringView locale, StringView calendar); -Vector get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton); -Vector get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton); - -Optional get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Era value); -Optional get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Month value); -Optional get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Weekday value); -Optional get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::DayPeriod value); -Optional get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour); - -Optional time_zone_from_string(StringView time_zone); -Optional get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style); - -} - } )~~~"); @@ -1567,6 +1538,8 @@ static void generate_unicode_locale_implementation(Core::File& file, UnicodeLoca generator.append(R"~~~( #include #include +#include +#include #include #include #include @@ -1578,7 +1551,7 @@ namespace Unicode::Detail { generator.append(R"~~~( template -void convert_calendar_fields(SourceType const& source, TargetType& target) +static void convert_calendar_fields(SourceType const& source, TargetType& target) { if (source.era != -1) target.era = static_cast(source.era); @@ -1800,6 +1773,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~"); append_from_string("TimeZone"sv, "time_zone"sv, locale_data.time_zones); generator.append(R"~~~( +Vector get_regional_hour_cycles(StringView region) asm("unicode_get_regional_hour_cycles"); Vector get_regional_hour_cycles(StringView region) { auto region_value = hour_cycle_region_from_string(region); @@ -1839,6 +1813,7 @@ static CalendarData const* find_calendar_data(StringView locale, StringView cale return &s_calendars[calendar_index]; } +Optional get_calendar_date_format(StringView locale, StringView calendar) asm("unicode_get_calendar_date_format"); Optional get_calendar_date_format(StringView locale, StringView calendar) { if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1848,6 +1823,7 @@ Optional get_calendar_date_format(StringView locale, St return {}; } +Optional get_calendar_time_format(StringView locale, StringView calendar) asm("unicode_get_calendar_time_format"); Optional get_calendar_time_format(StringView locale, StringView calendar) { if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1857,6 +1833,7 @@ Optional get_calendar_time_format(StringView locale, St return {}; } +Optional get_calendar_date_time_format(StringView locale, StringView calendar) asm("unicode_get_calendar_date_time_format"); Optional get_calendar_date_time_format(StringView locale, StringView calendar) { if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1866,6 +1843,7 @@ Optional get_calendar_date_time_format(StringView local return {}; } +Vector get_calendar_available_formats(StringView locale, StringView calendar) asm("unicode_get_calendar_available_formats"); Vector get_calendar_available_formats(StringView locale, StringView calendar) { Vector result {}; @@ -1881,6 +1859,7 @@ Vector get_calendar_available_formats(StringView local return result; } +Optional get_calendar_default_range_format(StringView locale, StringView calendar) asm("unicode_get_calendar_default_range_format"); Optional get_calendar_default_range_format(StringView locale, StringView calendar) { if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1891,7 +1870,9 @@ Optional get_calendar_default_range_format(String return {}; } -Vector get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton) { +Vector get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton) asm("unicode_get_calendar_range_formats"); +Vector get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton) +{ Vector result {}; if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1908,7 +1889,9 @@ Vector get_calendar_range_formats(StringView loca return result; } -Vector get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton) { +Vector get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton) asm("unicode_get_calendar_range12_formats"); +Vector get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton) +{ Vector result {}; if (auto const* data = find_calendar_data(locale, calendar); data != nullptr) { @@ -1956,7 +1939,8 @@ static Span<@string_index_type@ const> find_calendar_symbols(StringView locale, return {}; } -Optional get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Era value) +Optional get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value) asm("unicode_get_calendar_era_symbol"); +Optional get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value) { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Era, style); @@ -1966,7 +1950,8 @@ Optional get_calendar_era_symbol(StringView locale, StringView calen return {}; } -Optional get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Month value) +Optional get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value) asm("unicode_get_calendar_month_symbol"); +Optional get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value) { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Month, style); @@ -1976,7 +1961,8 @@ Optional get_calendar_month_symbol(StringView locale, StringView cal return {}; } -Optional get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Weekday value) +Optional get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value) asm("unicode_get_calendar_weekday_symbol"); +Optional get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value) { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::Weekday, style); @@ -1986,7 +1972,8 @@ Optional get_calendar_weekday_symbol(StringView locale, StringView c return {}; } -Optional get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::DayPeriod value) +Optional get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value) asm("unicode_get_calendar_day_period_symbol"); +Optional get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value) { auto symbols = find_calendar_symbols(locale, calendar, CalendarSymbol::DayPeriod, style); @@ -1996,6 +1983,7 @@ Optional get_calendar_day_period_symbol(StringView locale, StringVie return {}; } +Optional get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour) asm("unicode_get_calendar_day_period_symbol_for_hour"); Optional get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour) { auto locale_value = locale_from_string(locale); @@ -2043,6 +2031,7 @@ static TimeZoneData const* find_time_zone_data(StringView locale, StringView tim return &s_time_zones[time_zone_index]; } +Optional get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style) asm("unicode_get_time_zone_name"); Optional get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style) { if (auto const* data = find_time_zone_data(locale, time_zone); data != nullptr) { diff --git a/Userland/Libraries/LibUnicode/DateTimeFormat.cpp b/Userland/Libraries/LibUnicode/DateTimeFormat.cpp index 605d87e030..96a47fd3c6 100644 --- a/Userland/Libraries/LibUnicode/DateTimeFormat.cpp +++ b/Userland/Libraries/LibUnicode/DateTimeFormat.cpp @@ -8,10 +8,7 @@ #include #include #include - -#if ENABLE_UNICODE_DATA -# include -#endif +#include namespace Unicode { @@ -78,17 +75,14 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style) } // https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table -Vector get_regional_hour_cycles([[maybe_unused]] StringView locale) +Vector get_regional_hour_cycles(StringView locale) { -#if ENABLE_UNICODE_DATA - if (auto hour_cycles = Detail::get_regional_hour_cycles(locale); !hour_cycles.is_empty()) + static auto const& symbols = Detail::Symbols::ensure_loaded(); + + if (auto hour_cycles = symbols.get_regional_hour_cycles(locale); !hour_cycles.is_empty()) return hour_cycles; - auto return_default_hour_cycles = []() { - auto hour_cycles = Detail::get_regional_hour_cycles("001"sv); - VERIFY(!hour_cycles.is_empty()); - return hour_cycles; - }; + auto return_default_hour_cycles = [&]() { return symbols.get_regional_hour_cycles("001"sv); }; auto language = parse_unicode_language_id(locale); if (!language.has_value()) @@ -99,13 +93,10 @@ Vector get_regional_hour_cycles([[maybe_unused]] StringView if (!language.has_value() || !language->region.has_value()) return return_default_hour_cycles(); - if (auto hour_cycles = Detail::get_regional_hour_cycles(*language->region); !hour_cycles.is_empty()) + if (auto hour_cycles = symbols.get_regional_hour_cycles(*language->region); !hour_cycles.is_empty()) return hour_cycles; return return_default_hour_cycles(); -#else - return {}; -#endif } Optional get_default_regional_hour_cycle(StringView locale) @@ -156,112 +147,80 @@ String combine_skeletons(StringView first, StringView second) return builder.build(); } -Optional get_calendar_format([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarFormatType type) +Optional get_calendar_format(StringView locale, StringView calendar, CalendarFormatType type) { -#if ENABLE_UNICODE_DATA + static auto const& symbols = Detail::Symbols::ensure_loaded(); + switch (type) { case CalendarFormatType::Date: - return Detail::get_calendar_date_format(locale, calendar); + return symbols.get_calendar_date_format(locale, calendar); case CalendarFormatType::Time: - return Detail::get_calendar_time_format(locale, calendar); + return symbols.get_calendar_time_format(locale, calendar); case CalendarFormatType::DateTime: - return Detail::get_calendar_date_time_format(locale, calendar); + return symbols.get_calendar_date_time_format(locale, calendar); default: VERIFY_NOT_REACHED(); } -#else - return {}; -#endif } -Vector get_calendar_available_formats([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar) +Vector get_calendar_available_formats(StringView locale, StringView calendar) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_available_formats(locale, calendar); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_available_formats(locale, calendar); } -Optional get_calendar_default_range_format([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar) +Optional get_calendar_default_range_format(StringView locale, StringView calendar) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_default_range_format(locale, calendar); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_default_range_format(locale, calendar); } -Vector get_calendar_range_formats([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] StringView skeleton) +Vector get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_range_formats(locale, calendar, skeleton); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_range_formats(locale, calendar, skeleton); } -Vector get_calendar_range12_formats([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] StringView skeleton) +Vector get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_range12_formats(locale, calendar, skeleton); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_range12_formats(locale, calendar, skeleton); } -Optional get_calendar_era_symbol([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarPatternStyle style, [[maybe_unused]] Unicode::Era value) +Optional get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Era value) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_era_symbol(locale, calendar, style, value); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_era_symbol(locale, calendar, style, value); } -Optional get_calendar_month_symbol([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarPatternStyle style, [[maybe_unused]] Unicode::Month value) +Optional get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Month value) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_month_symbol(locale, calendar, style, value); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_month_symbol(locale, calendar, style, value); } -Optional get_calendar_weekday_symbol([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarPatternStyle style, [[maybe_unused]] Unicode::Weekday value) +Optional get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Weekday value) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_weekday_symbol(locale, calendar, style, value); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_weekday_symbol(locale, calendar, style, value); } -Optional get_calendar_day_period_symbol([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarPatternStyle style, [[maybe_unused]] Unicode::DayPeriod value) +Optional get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::DayPeriod value) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_day_period_symbol(locale, calendar, style, value); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_day_period_symbol(locale, calendar, style, value); } -Optional get_calendar_day_period_symbol_for_hour([[maybe_unused]] StringView locale, [[maybe_unused]] StringView calendar, [[maybe_unused]] CalendarPatternStyle style, [[maybe_unused]] u8 hour) +Optional get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour) { -#if ENABLE_UNICODE_DATA - return Detail::get_calendar_day_period_symbol_for_hour(locale, calendar, style, hour); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_calendar_day_period_symbol_for_hour(locale, calendar, style, hour); } -Optional get_time_zone_name([[maybe_unused]] StringView locale, [[maybe_unused]] StringView time_zone, [[maybe_unused]] CalendarPatternStyle style) +Optional get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style) { -#if ENABLE_UNICODE_DATA - return Detail::get_time_zone_name(locale, time_zone, style); -#else - return {}; -#endif + static auto const& symbols = Detail::Symbols::ensure_loaded(); + return symbols.get_time_zone_name(locale, time_zone, style); } } diff --git a/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp b/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp index 76898ded47..5e254ea134 100644 --- a/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp +++ b/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp @@ -15,6 +15,7 @@ # endif #else # include +# include # include # include #endif @@ -117,6 +118,21 @@ Symbols const& Symbols::ensure_loaded() load_symbol(symbols.get_compact_number_system_formats, "unicode_get_compact_number_system_formats"); load_symbol(symbols.get_unit_formats, "unicode_get_unit_formats"); + load_symbol(symbols.get_regional_hour_cycles, "unicode_get_regional_hour_cycles"); + load_symbol(symbols.get_calendar_date_format, "unicode_get_calendar_date_format"); + load_symbol(symbols.get_calendar_time_format, "unicode_get_calendar_time_format"); + load_symbol(symbols.get_calendar_date_time_format, "unicode_get_calendar_date_time_format"); + load_symbol(symbols.get_calendar_available_formats, "unicode_get_calendar_available_formats"); + load_symbol(symbols.get_calendar_default_range_format, "unicode_get_calendar_default_range_format"); + load_symbol(symbols.get_calendar_range_formats, "unicode_get_calendar_range_formats"); + load_symbol(symbols.get_calendar_range12_formats, "unicode_get_calendar_range12_formats"); + load_symbol(symbols.get_calendar_era_symbol, "unicode_get_calendar_era_symbol"); + load_symbol(symbols.get_calendar_month_symbol, "unicode_get_calendar_month_symbol"); + load_symbol(symbols.get_calendar_weekday_symbol, "unicode_get_calendar_weekday_symbol"); + load_symbol(symbols.get_calendar_day_period_symbol, "unicode_get_calendar_day_period_symbol"); + load_symbol(symbols.get_calendar_day_period_symbol_for_hour, "unicode_get_calendar_day_period_symbol_for_hour"); + load_symbol(symbols.get_time_zone_name, "unicode_get_time_zone_name"); + initialized = true; return symbols; } diff --git a/Userland/Libraries/LibUnicode/UnicodeSymbols.h b/Userland/Libraries/LibUnicode/UnicodeSymbols.h index b2d662f4e9..4b0cd1ef0f 100644 --- a/Userland/Libraries/LibUnicode/UnicodeSymbols.h +++ b/Userland/Libraries/LibUnicode/UnicodeSymbols.h @@ -72,6 +72,27 @@ struct Symbols { Vector (*get_compact_number_system_formats)(StringView, StringView, CompactNumberFormatType); Vector (*get_unit_formats)(StringView, StringView, Style); + // Loaded from UnicodeDateTimeFormat.cpp: + + Vector (*get_regional_hour_cycles)(StringView) { nullptr }; + + Optional (*get_calendar_date_format)(StringView, StringView) { nullptr }; + Optional (*get_calendar_time_format)(StringView, StringView) { nullptr }; + Optional (*get_calendar_date_time_format)(StringView, StringView) { nullptr }; + Vector (*get_calendar_available_formats)(StringView, StringView) { nullptr }; + + Optional (*get_calendar_default_range_format)(StringView, StringView) { nullptr }; + Vector (*get_calendar_range_formats)(StringView, StringView, StringView) { nullptr }; + Vector (*get_calendar_range12_formats)(StringView, StringView, StringView) { nullptr }; + + Optional (*get_calendar_era_symbol)(StringView, StringView, CalendarPatternStyle, Era) { nullptr }; + Optional (*get_calendar_month_symbol)(StringView, StringView, CalendarPatternStyle, Month) { nullptr }; + Optional (*get_calendar_weekday_symbol)(StringView, StringView, CalendarPatternStyle, Weekday) { nullptr }; + Optional (*get_calendar_day_period_symbol)(StringView, StringView, CalendarPatternStyle, DayPeriod) { nullptr }; + Optional (*get_calendar_day_period_symbol_for_hour)(StringView, StringView, CalendarPatternStyle, u8) { nullptr }; + + Optional (*get_time_zone_name)(StringView, StringView, CalendarPatternStyle) { nullptr }; + private: Symbols() = default; };