/* * Copyright (c) 2021-2024, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace JS::Intl { using LocaleKey = Variant; Optional locale_key_from_value(Value); struct LocaleOptions { Value locale_matcher; Optional ca; // [[Calendar]] Optional co; // [[Collation]] Optional hc; // [[HourCycle]] Optional kf; // [[CaseFirst]] Optional kn; // [[Numeric]] Optional nu; // [[NumberingSystem]] }; struct MatchedLocale { String locale; Optional extension; }; struct ResolvedLocale { String locale; LocaleKey ca; // [[Calendar]] LocaleKey co; // [[Collation]] LocaleKey hc; // [[HourCycle]] LocaleKey kf; // [[CaseFirst]] LocaleKey kn; // [[Numeric]] LocaleKey nu; // [[NumberingSystem]] }; using StringOrBoolean = Variant; bool is_structurally_valid_language_tag(StringView locale); String canonicalize_unicode_locale_id(StringView locale); bool is_well_formed_currency_code(StringView currency); Vector const& available_named_time_zone_identifiers(); Optional get_available_named_time_zone_identifier(StringView time_zone_identifier); bool is_well_formed_unit_identifier(StringView unit_identifier); ThrowCompletionOr> canonicalize_locale_list(VM&, Value locales); Optional lookup_matching_locale_by_prefix(ReadonlySpan requested_locales); Optional lookup_matching_locale_by_best_fit(ReadonlySpan requested_locales); String insert_unicode_extension_and_canonicalize(Unicode::LocaleID locale_id, Vector attributes, Vector keywords); ResolvedLocale resolve_locale(ReadonlySpan requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys); ThrowCompletionOr filter_locales(VM& vm, ReadonlySpan requested_locales, Value options); ThrowCompletionOr coerce_options_to_object(VM&, Value options); ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, ReadonlySpan string_values, StringOrBoolean fallback); ThrowCompletionOr> default_number_option(VM&, Value value, int minimum, int maximum, Optional fallback); ThrowCompletionOr> get_number_option(VM&, Object const& options, PropertyKey const& property, int minimum, int maximum, Optional fallback); template ThrowCompletionOr get_boolean_or_string_number_format_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&string_values)[Size], StringOrBoolean fallback) { return get_boolean_or_string_number_format_option(vm, options, property, ReadonlySpan { string_values }, move(fallback)); } // NOTE: ECMA-402's GetOption is being removed in favor of a shared ECMA-262 GetOption in the Temporal proposal. // Until Temporal is merged into ECMA-262, our implementation lives in the Temporal-specific AO file & namespace. using Temporal::get_option; using Temporal::OptionType; }