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