/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace JS::Intl { using Fallback = Variant; struct LocaleOptions { Value locale_matcher; Optional ca; // [[Calendar]] Optional co; // [[Collation]] Optional hc; // [[HourCycle]] Optional kf; // [[CaseFirst]] Optional kn; // [[Numeric]] Optional nu; // [[NumberingSystem]] }; struct LocaleResult { String locale; String data_locale; Optional ca; // [[Calendar]] Optional co; // [[Collation]] Optional hc; // [[HourCycle]] Optional kf; // [[CaseFirst]] Optional kn; // [[Numeric]] Optional nu; // [[NumberingSystem]] }; struct PatternPartition { PatternPartition() = default; PatternPartition(StringView type_string, String value_string) : type(type_string) , value(move(value_string)) { } StringView type; String value; }; constexpr auto sanctioned_simple_unit_identifiers() { return AK::Array { "acre"sv, "bit"sv, "byte"sv, "celsius"sv, "centimeter"sv, "day"sv, "degree"sv, "fahrenheit"sv, "fluid-ounce"sv, "foot"sv, "gallon"sv, "gigabit"sv, "gigabyte"sv, "gram"sv, "hectare"sv, "hour"sv, "inch"sv, "kilobit"sv, "kilobyte"sv, "kilogram"sv, "kilometer"sv, "liter"sv, "megabit"sv, "megabyte"sv, "meter"sv, "mile"sv, "mile-scandinavian"sv, "milliliter"sv, "millimeter"sv, "millisecond"sv, "minute"sv, "month"sv, "ounce"sv, "percent"sv, "petabyte"sv, "pound"sv, "second"sv, "stone"sv, "terabit"sv, "terabyte"sv, "week"sv, "yard"sv, "year"sv }; } Optional is_structurally_valid_language_tag(StringView locale); String canonicalize_unicode_locale_id(Unicode::LocaleID& locale); bool is_well_formed_currency_code(StringView currency); bool is_well_formed_unit_identifier(StringView unit_identifier); ThrowCompletionOr> canonicalize_locale_list(GlobalObject&, Value locales); Optional best_available_locale(StringView locale); String insert_unicode_extension_and_canonicalize(Unicode::LocaleID locale_id, Unicode::LocaleExtension extension); LocaleResult resolve_locale(Vector const& requested_locales, LocaleOptions const& options, Span relevant_extension_keys); Vector lookup_supported_locales(Vector const& requested_locales); Vector best_fit_supported_locales(Vector const& requested_locales); ThrowCompletionOr supported_locales(GlobalObject&, Vector const& requested_locales, Value options); ThrowCompletionOr coerce_options_to_object(GlobalObject& global_object, Value options); ThrowCompletionOr get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, Value::Type type, Span values, Fallback fallback); ThrowCompletionOr> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional fallback); ThrowCompletionOr> get_number_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional fallback); Vector partition_pattern(StringView pattern); template ThrowCompletionOr get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, Value::Type type, StringView const (&values)[Size], Fallback fallback) { return get_option(global_object, options, property, type, Span { values }, fallback); } }