/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace JS::Intl { 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; }; struct PatternPartitionWithSource : public PatternPartition { static ThrowCompletionOr> create_from_parent_list(VM& vm, Vector partitions) { Vector result; TRY_OR_THROW_OOM(vm, result.try_ensure_capacity(partitions.size())); for (auto& partition : partitions) { PatternPartitionWithSource partition_with_source {}; partition_with_source.type = partition.type; partition_with_source.value = move(partition.value); result.unchecked_append(move(partition_with_source)); } return result; } bool operator==(PatternPartitionWithSource const& other) const { return (type == other.type) && (value == other.value) && (source == other.source); } StringView source; }; using StringOrBoolean = Variant; ThrowCompletionOr> is_structurally_valid_language_tag(VM&, StringView locale); ThrowCompletionOr canonicalize_unicode_locale_id(VM&, ::Locale::LocaleID& locale); bool is_well_formed_currency_code(StringView currency); bool is_well_formed_unit_identifier(StringView unit_identifier); ThrowCompletionOr> canonicalize_locale_list(VM&, Value locales); Optional best_available_locale(StringView locale); ThrowCompletionOr insert_unicode_extension_and_canonicalize(VM&, ::Locale::LocaleID locale_id, ::Locale::LocaleExtension extension); ThrowCompletionOr resolve_locale(VM&, Vector const& requested_locales, LocaleOptions const& options, ReadonlySpan relevant_extension_keys); ThrowCompletionOr supported_locales(VM&, Vector const& 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); ThrowCompletionOr> partition_pattern(VM&, StringView pattern); 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; }