/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #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 { DeprecatedString locale; DeprecatedString 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, DeprecatedString value_string) : type(type_string) , value(move(value_string)) { } StringView type; DeprecatedString value; }; struct PatternPartitionWithSource : public PatternPartition { static Vector create_from_parent_list(Vector partitions) { Vector result; result.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.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; Optional<::Locale::LocaleID> is_structurally_valid_language_tag(StringView locale); DeprecatedString canonicalize_unicode_locale_id(::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); DeprecatedString insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale_id, ::Locale::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(VM&, Vector const& requested_locales, Value options); ThrowCompletionOr coerce_options_to_object(VM&, Value options); ThrowCompletionOr get_string_or_boolean_option(VM&, Object const& options, PropertyKey const& property, Span values, StringOrBoolean true_value, StringOrBoolean falsy_value, 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); Vector partition_pattern(StringView pattern); template ThrowCompletionOr get_string_or_boolean_option(VM& vm, Object const& options, PropertyKey const& property, StringView const (&values)[Size], StringOrBoolean true_value, StringOrBoolean falsy_value, StringOrBoolean fallback) { return get_string_or_boolean_option(vm, options, property, Span { values }, move(true_value), move(falsy_value), 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; }