1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:27:34 +00:00

Userland: Move files destined for LibLocale to the Locale namespace

This commit is contained in:
Timothy Flynn 2022-09-02 12:01:10 -04:00 committed by Tim Flynn
parent 88504b89e1
commit ff48220dca
55 changed files with 720 additions and 716 deletions

View file

@ -163,17 +163,17 @@ static bool is_followed_by_combining_dot_above(Utf8View const& string, size_t in
static SpecialCasing const* find_matching_special_case(u32 code_point, Utf8View const& string, Optional<StringView> locale, size_t index, size_t byte_length)
{
auto requested_locale = Locale::None;
auto requested_locale = Locale::Locale::None;
if (locale.has_value()) {
if (auto maybe_locale = locale_from_string(*locale); maybe_locale.has_value())
if (auto maybe_locale = Locale::locale_from_string(*locale); maybe_locale.has_value())
requested_locale = *maybe_locale;
}
auto special_casings = special_case_mapping(code_point);
for (auto const* special_casing : special_casings) {
if (special_casing->locale != Locale::None && special_casing->locale != requested_locale)
if (special_casing->locale != Locale::Locale::None && special_casing->locale != requested_locale)
continue;
switch (special_casing->condition) {

View file

@ -11,18 +11,18 @@
#include <LibUnicode/NumberFormat.h>
#include <stdlib.h>
namespace Unicode {
namespace Locale {
HourCycle hour_cycle_from_string(StringView hour_cycle)
{
if (hour_cycle == "h11"sv)
return Unicode::HourCycle::H11;
return HourCycle::H11;
else if (hour_cycle == "h12"sv)
return Unicode::HourCycle::H12;
return HourCycle::H12;
else if (hour_cycle == "h23"sv)
return Unicode::HourCycle::H23;
return HourCycle::H23;
else if (hour_cycle == "h24"sv)
return Unicode::HourCycle::H24;
return HourCycle::H24;
VERIFY_NOT_REACHED();
}
@ -125,12 +125,12 @@ static auto find_regional_values_for_locale(StringView locale, GetRegionalValues
}
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
Vector<Unicode::HourCycle> get_locale_hour_cycles(StringView locale)
Vector<HourCycle> get_locale_hour_cycles(StringView locale)
{
return find_regional_values_for_locale(locale, get_regional_hour_cycles);
}
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale)
Optional<HourCycle> get_default_regional_hour_cycle(StringView locale)
{
if (auto hour_cycles = get_locale_hour_cycles(locale); !hour_cycles.is_empty())
return hour_cycles.first();

View file

@ -15,7 +15,7 @@
#include <LibTimeZone/TimeZone.h>
#include <LibUnicode/Forward.h>
namespace Unicode {
namespace Locale {
enum class Era : u8 {
BC,
@ -189,8 +189,8 @@ StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
Optional<HourCycleRegion> hour_cycle_region_from_string(StringView hour_cycle_region);
Vector<HourCycle> get_regional_hour_cycles(StringView region);
Vector<Unicode::HourCycle> get_locale_hour_cycles(StringView locale);
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale);
Vector<HourCycle> get_locale_hour_cycles(StringView locale);
Optional<HourCycle> get_default_regional_hour_cycle(StringView locale);
Optional<MinimumDaysRegion> minimum_days_region_from_string(StringView minimum_days_region);
Optional<u8> get_regional_minimum_days(StringView region);
@ -215,14 +215,14 @@ Optional<CalendarFormat> get_calendar_time_format(StringView locale, StringView
Optional<CalendarFormat> get_calendar_date_time_format(StringView locale, StringView calendar);
Optional<CalendarFormat> get_calendar_format(StringView locale, StringView calendar, CalendarFormatType type);
Vector<CalendarPattern> get_calendar_available_formats(StringView locale, StringView calendar);
Optional<Unicode::CalendarRangePattern> get_calendar_default_range_format(StringView locale, StringView calendar);
Vector<Unicode::CalendarRangePattern> get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton);
Vector<Unicode::CalendarRangePattern> get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton);
Optional<CalendarRangePattern> get_calendar_default_range_format(StringView locale, StringView calendar);
Vector<CalendarRangePattern> get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton);
Vector<CalendarRangePattern> get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton);
Optional<StringView> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Era value);
Optional<StringView> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Month value);
Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Weekday value);
Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::DayPeriod value);
Optional<StringView> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value);
Optional<StringView> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value);
Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value);
Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
String format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);

View file

@ -11,6 +11,20 @@
namespace Unicode {
enum class Block : u16;
enum class GeneralCategory : u8;
enum class GraphemeBreakProperty : u8;
enum class Property : u8;
enum class Script : u8;
enum class SentenceBreakProperty : u8;
enum class WordBreakProperty : u8;
struct CurrencyCode;
struct SpecialCasing;
}
namespace Locale {
enum class CalendarFormatType : u8;
enum class CalendarPatternStyle : u8;
enum class CalendarSymbol : u8;
@ -22,8 +36,6 @@ enum class DateField : u8;
enum class DayPeriod : u8;
enum class Era : u8;
enum class FirstDayRegion : u8;
enum class GeneralCategory : u8;
enum class GraphemeBreakProperty : u8;
enum class HourCycle : u8;
enum class HourCycleRegion : u16;
enum class Key : u8;
@ -34,29 +46,23 @@ enum class KeywordColNumeric : u8;
enum class KeywordHours : u8;
enum class KeywordNumbers : u8;
enum class Language : u16;
enum class ListPatternStyle : u8;
enum class ListPatternType : u8;
enum class Locale : u16;
enum class MinimumDaysRegion : u8;
enum class Month : u8;
enum class NumericSymbol : u8;
enum class PluralCategory : u8;
enum class Property : u8;
enum class Script : u8;
enum class ScriptTag : u8;
enum class SentenceBreakProperty : u8;
enum class StandardNumberFormatType : u8;
enum class Style : u8;
enum class Territory : u8;
enum class Weekday : u8;
enum class WeekendEndRegion : u8;
enum class WeekendStartRegion : u8;
enum class WordBreakProperty : u8;
struct CalendarFormat;
struct CalendarPattern;
struct CalendarRangePattern;
struct CurrencyCode;
struct Keyword;
struct LanguageID;
struct ListPatterns;
@ -66,9 +72,7 @@ struct NumberFormat;
struct NumberGroupings;
struct OtherExtension;
struct PluralOperands;
struct SpecialCasing;
struct TransformedExtension;
struct TransformedField;
struct UnicodeData;
}

View file

@ -12,7 +12,7 @@
#include <LibUnicode/DateTimeFormat.h>
#include <LibUnicode/Locale.h>
namespace Unicode {
namespace Locale {
static bool is_key(StringView key)
{
@ -809,7 +809,7 @@ Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id
auto language_id = move(locale_id.language_id);
VERIFY(language_id.language.has_value());
auto patterns = Unicode::get_locale_display_patterns(locale);
auto patterns = get_locale_display_patterns(locale);
if (!patterns.has_value())
return {};

View file

@ -14,7 +14,7 @@
#include <AK/Vector.h>
#include <LibUnicode/Forward.h>
namespace Unicode {
namespace Locale {
struct LanguageID {
String to_string() const;
@ -206,7 +206,7 @@ void resolve_complex_language_aliases(LanguageID& language_id);
Optional<LanguageID> add_likely_subtags(LanguageID const& language_id);
Optional<LanguageID> remove_likely_subtags(LanguageID const& language_id);
Optional<String> resolve_most_likely_territory(Unicode::LanguageID const& language_id);
Optional<String> resolve_most_likely_territory(LanguageID const& language_id);
String resolve_most_likely_territory_alias(LanguageID const& language_id, StringView territory_alias);
}

View file

@ -14,7 +14,7 @@
# include <LibUnicode/UnicodeData.h>
#endif
namespace Unicode {
namespace Locale {
Optional<StringView> __attribute__((weak)) get_number_system_symbol(StringView, StringView, NumericSymbol) { return {}; }
Optional<NumberGroupings> __attribute__((weak)) get_number_system_groupings(StringView, StringView) { return {}; }
@ -83,19 +83,19 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
if (*number_index < *currency_index) {
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *currency_index));
if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) {
if (!Unicode::code_point_has_general_category(last_pattern_code_point, Unicode::GeneralCategory::Separator)) {
u32 first_currency_code_point = *utf8_currency_display.begin();
if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol))
if (!Unicode::code_point_has_general_category(first_currency_code_point, Unicode::GeneralCategory::Symbol))
currency_key_with_spacing = String::formatted("{}{}", spacing, currency_key);
}
} else {
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *number_index));
if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) {
if (!Unicode::code_point_has_general_category(last_pattern_code_point, Unicode::GeneralCategory::Separator)) {
u32 last_currency_code_point = last_code_point(currency_display);
if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol))
if (!Unicode::code_point_has_general_category(last_currency_code_point, Unicode::GeneralCategory::Symbol))
currency_key_with_spacing = String::formatted("{}{}", currency_key, spacing);
}
}
@ -123,17 +123,17 @@ Optional<String> augment_range_pattern([[maybe_unused]] StringView range_separat
// To determine whether to add spacing, the currently recommended heuristic is:
// 2. If the range pattern does not contain a character having the White_Space binary Unicode property after the {0} or before the {1} placeholders.
for (auto it = utf8_range_separator.begin(); it != utf8_range_separator.end(); ++it) {
if (code_point_has_property(*it, Property::White_Space))
if (Unicode::code_point_has_property(*it, Unicode::Property::White_Space))
return {};
}
// 1. If the lower string ends with a character other than a digit, or if the upper string begins with a character other than a digit.
if (auto it = utf8_upper.begin(); it != utf8_upper.end()) {
if (!code_point_has_general_category(*it, GeneralCategory::Decimal_Number))
if (!Unicode::code_point_has_general_category(*it, Unicode::GeneralCategory::Decimal_Number))
return range_pattern_with_spacing();
}
if (!code_point_has_general_category(last_code_point(lower), GeneralCategory::Decimal_Number))
if (!Unicode::code_point_has_general_category(last_code_point(lower), Unicode::GeneralCategory::Decimal_Number))
return range_pattern_with_spacing();
#endif

View file

@ -13,7 +13,7 @@
#include <LibUnicode/Forward.h>
#include <LibUnicode/PluralRules.h>
namespace Unicode {
namespace Locale {
struct NumberGroupings {
u8 minimum_grouping_digits { 0 };

View file

@ -6,7 +6,7 @@
#include <LibUnicode/PluralRules.h>
namespace Unicode {
namespace Locale {
PluralForm plural_form_from_string(StringView plural_form)
{

View file

@ -11,7 +11,7 @@
#include <AK/Types.h>
#include <LibUnicode/Forward.h>
namespace Unicode {
namespace Locale {
enum class PluralForm {
Cardinal,

View file

@ -6,7 +6,7 @@
#include <LibUnicode/RelativeTimeFormat.h>
namespace Unicode {
namespace Locale {
Optional<TimeUnit> time_unit_from_string(StringView time_unit)
{

View file

@ -12,7 +12,7 @@
#include <LibUnicode/Forward.h>
#include <LibUnicode/Locale.h>
namespace Unicode {
namespace Locale {
// These are just the subset of fields in the CLDR required for ECMA-402.
enum class TimeUnit {