2021-08-24 23:58:45 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
|
|
|
|
#include <AK/Variant.h>
|
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
#include <LibJS/Runtime/Intl/DisplayNames.h>
|
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
2021-09-01 23:08:15 -03:00
|
|
|
#include <LibUnicode/Forward.h>
|
2021-08-24 23:58:45 -03:00
|
|
|
|
|
|
|
|
namespace JS::Intl {
|
|
|
|
|
|
|
|
|
|
using Fallback = Variant<Empty, bool, StringView>;
|
|
|
|
|
|
|
|
|
|
struct LocaleOptions {
|
|
|
|
|
Value locale_matcher;
|
2021-09-10 12:04:54 -03:00
|
|
|
Optional<String> nu;
|
2021-08-24 23:58:45 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct LocaleResult {
|
|
|
|
|
String locale;
|
2021-09-10 11:01:41 -03:00
|
|
|
String data_locale;
|
2021-09-10 12:04:54 -03:00
|
|
|
Optional<String> nu;
|
2021-08-24 23:58:45 -03:00
|
|
|
};
|
|
|
|
|
|
2021-09-06 15:37:23 -03:00
|
|
|
struct PatternPartition {
|
|
|
|
|
StringView type;
|
|
|
|
|
StringView value;
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-01 23:08:15 -03:00
|
|
|
Optional<Unicode::LocaleID> is_structurally_valid_language_tag(StringView locale);
|
2021-09-11 08:58:33 -03:00
|
|
|
String canonicalize_unicode_locale_id(Unicode::LocaleID& locale);
|
2021-09-10 12:04:54 -03:00
|
|
|
bool is_well_formed_currency_code(StringView currency);
|
|
|
|
|
bool is_well_formed_unit_identifier(StringView unit_identifier);
|
2021-09-18 13:24:28 -03:00
|
|
|
ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject&, Value locales);
|
2021-09-05 16:27:11 -03:00
|
|
|
Optional<String> best_available_locale(StringView const& locale);
|
2021-09-11 08:58:33 -03:00
|
|
|
String insert_unicode_extension_and_canonicalize(Unicode::LocaleID locale_id, Unicode::LocaleExtension extension);
|
|
|
|
|
LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptions const& options, Vector<StringView> const& relevant_extension_keys);
|
2021-09-04 13:08:57 -03:00
|
|
|
Vector<String> lookup_supported_locales(Vector<String> const& requested_locales);
|
2021-09-11 08:58:33 -03:00
|
|
|
Vector<String> best_fit_supported_locales(Vector<String> const& requested_locales);
|
2021-09-18 13:32:51 -03:00
|
|
|
ThrowCompletionOr<Array*> supported_locales(GlobalObject&, Vector<String> const& requested_locales, Value options);
|
2021-09-18 13:33:45 -03:00
|
|
|
ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object, Value options);
|
2021-09-18 13:31:17 -03:00
|
|
|
ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback);
|
2021-09-18 13:37:39 -03:00
|
|
|
ThrowCompletionOr<Optional<int>> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback);
|
2021-09-18 13:38:29 -03:00
|
|
|
ThrowCompletionOr<Optional<int>> get_number_option(GlobalObject& global_object, Object const& options, PropertyName const& property, int minimum, int maximum, Optional<int> fallback);
|
2021-09-06 15:37:23 -03:00
|
|
|
Vector<PatternPartition> partition_pattern(StringView pattern);
|
2021-08-24 23:58:45 -03:00
|
|
|
|
|
|
|
|
}
|