LibUnicode+Everywhere: Merge LibLocale back into LibUnicode

LibLocale was split off from LibUnicode a couple years ago to reduce the
number of applications on SerenityOS that depend on CLDR data. Now that
we use ICU, both LibUnicode and LibLocale are actually linking in this
data. And since vcpkg gives us static libraries, both libraries are over
30MB in size.

This patch reverts the separation and merges LibLocale into LibUnicode
again. We now have just one library that includes the ICU data.

Further, this will let LibUnicode share the locale cache that previously
would only exist in LibLocale.
This commit is contained in:
Timothy Flynn 2024-06-23 09:14:27 -04:00 committed by Andreas Kling
parent c9d9e1bb1f
commit ebdb92eef6
Notes: sideshowbarker 2024-07-16 16:23:32 +09:00
102 changed files with 675 additions and 711 deletions

1
.github/CODEOWNERS vendored
View File

@ -10,7 +10,6 @@
/Userland/Libraries/LibCrypto @alimpfard /Userland/Libraries/LibCrypto @alimpfard
/Userland/Libraries/LibHTTP @alimpfard /Userland/Libraries/LibHTTP @alimpfard
/Userland/Libraries/LibJS/Runtime/Intl @trflynn89 /Userland/Libraries/LibJS/Runtime/Intl @trflynn89
/Userland/Libraries/LibLocale @trflynn89
/Userland/Libraries/LibRegex @alimpfard /Userland/Libraries/LibRegex @alimpfard
/Userland/Libraries/LibTLS @alimpfard /Userland/Libraries/LibTLS @alimpfard
/Userland/Libraries/LibTimeZone @trflynn89 /Userland/Libraries/LibTimeZone @trflynn89

View File

@ -22,7 +22,7 @@ add_library(webworker STATIC ${WEBWORKER_SOURCES})
target_include_directories(webworker PRIVATE ${LADYBIRD_SOURCE_DIR}/Userland/Services/) target_include_directories(webworker PRIVATE ${LADYBIRD_SOURCE_DIR}/Userland/Services/)
target_include_directories(webworker PRIVATE ${LADYBIRD_SOURCE_DIR}/Userland/) target_include_directories(webworker PRIVATE ${LADYBIRD_SOURCE_DIR}/Userland/)
target_include_directories(webworker PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..) target_include_directories(webworker PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
target_link_libraries(webworker PUBLIC LibCore LibFileSystem LibGfx LibIPC LibJS LibProtocol LibWeb LibWebView LibLocale LibImageDecoderClient LibMain LibURL) target_link_libraries(webworker PUBLIC LibCore LibFileSystem LibGfx LibIPC LibJS LibProtocol LibWeb LibWebView LibUnicode LibImageDecoderClient LibMain LibURL)
if (HAS_FONTCONFIG) if (HAS_FONTCONFIG)
target_link_libraries(webworker PRIVATE Fontconfig::Fontconfig) target_link_libraries(webworker PRIVATE Fontconfig::Fontconfig)

View File

@ -394,7 +394,6 @@ set(lagom_standard_libraries
IPC IPC
JS JS
Line Line
Locale
Media Media
Protocol Protocol
Regex Regex
@ -437,9 +436,6 @@ foreach(lib IN LISTS lagom_standard_libraries)
add_serenity_subdirectory("Userland/Libraries/Lib${lib}") add_serenity_subdirectory("Userland/Libraries/Lib${lib}")
endforeach() endforeach()
# FIXME: Why is this not in LibLocale/CMakeLists.txt?
target_link_libraries(LibLocale PRIVATE LibTimeZone)
if (ENABLE_FUZZERS) if (ENABLE_FUZZERS)
add_subdirectory(Fuzzers) add_subdirectory(Fuzzers)
endif() endif()
@ -460,7 +456,7 @@ lagom_utility(gzip SOURCES ../../Userland/Utilities/gzip.cpp LIBS LibCompress Li
lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL) lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL)
lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain) lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain)
lagom_utility(ttfdisasm SOURCES ../../Userland/Utilities/ttfdisasm.cpp LIBS LibGfx LibMain) lagom_utility(ttfdisasm SOURCES ../../Userland/Utilities/ttfdisasm.cpp LIBS LibGfx LibMain)
lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibLocale LibMain LibTextCodec Threads::Threads) lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibUnicode LibMain LibTextCodec Threads::Threads)
lagom_utility(lzcat SOURCES ../../Userland/Utilities/lzcat.cpp LIBS LibCompress LibMain) lagom_utility(lzcat SOURCES ../../Userland/Utilities/lzcat.cpp LIBS LibCompress LibMain)
@ -513,7 +509,6 @@ if (BUILD_TESTING)
LibCrypto LibCrypto
LibCompress LibCompress
LibGfx LibGfx
LibLocale
LibMedia LibMedia
LibTest LibTest
LibTextCodec LibTextCodec

View File

@ -25,7 +25,7 @@ At the moment, many core library support components are inherited from SerenityO
- LibHTTP: HTTP/1.1 client - LibHTTP: HTTP/1.1 client
- LibGfx: 2D Graphics Library, Image Decoding and Rendering - LibGfx: 2D Graphics Library, Image Decoding and Rendering
- LibArchive: Archive file format support - LibArchive: Archive file format support
- LibUnicode, LibLocale: Unicode and locale support - LibUnicode: Unicode and locale support
- LibAudio, LibMedia: Audio and video playback - LibAudio, LibMedia: Audio and video playback
- LibCore: Event loop, OS abstraction layer - LibCore: Event loop, OS abstraction layer
- LibIPC: Inter-process communication - LibIPC: Inter-process communication

View File

@ -5,7 +5,6 @@ add_subdirectory(LibCore)
add_subdirectory(LibDiff) add_subdirectory(LibDiff)
add_subdirectory(LibGfx) add_subdirectory(LibGfx)
add_subdirectory(LibJS) add_subdirectory(LibJS)
add_subdirectory(LibLocale)
add_subdirectory(LibRegex) add_subdirectory(LibRegex)
add_subdirectory(LibTest) add_subdirectory(LibTest)
add_subdirectory(LibTextCodec) add_subdirectory(LibTextCodec)

View File

@ -1,13 +1,13 @@
serenity_testjs_test(test-js.cpp test-js LIBS LibLocale) serenity_testjs_test(test-js.cpp test-js LIBS LibUnicode)
install(TARGETS test-js RUNTIME DESTINATION bin OPTIONAL) install(TARGETS test-js RUNTIME DESTINATION bin OPTIONAL)
serenity_test(test-invalid-unicode-js.cpp LibJS LIBS LibJS LibLocale) serenity_test(test-invalid-unicode-js.cpp LibJS LIBS LibJS LibUnicode)
serenity_test(test-value-js.cpp LibJS LIBS LibJS LibLocale) serenity_test(test-value-js.cpp LibJS LIBS LibJS LibUnicode)
add_executable(test262-runner test262-runner.cpp) add_executable(test262-runner test262-runner.cpp)
target_link_libraries(test262-runner PRIVATE LibJS LibCore LibLocale) target_link_libraries(test262-runner PRIVATE LibJS LibCore LibUnicode)
serenity_set_implicit_links(test262-runner) serenity_set_implicit_links(test262-runner)
install(TARGETS test262-runner RUNTIME DESTINATION bin OPTIONAL) install(TARGETS test262-runner RUNTIME DESTINATION bin OPTIONAL)

View File

@ -1,9 +0,0 @@
set(TEST_SOURCES
TestDisplayNames.cpp
TestLocale.cpp
TestSegmenter.cpp
)
foreach(source IN LISTS TEST_SOURCES)
serenity_test("${source}" LibLocale LIBS LibLocale)
endforeach()

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <LibLocale/DisplayNames.h>
#include <LibLocale/Locale.h>
TEST_CASE(locale_mappings_en)
{
auto language = Locale::language_display_name("en"sv, "en"sv, Locale::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "English"sv);
language = Locale::language_display_name("en"sv, "i-defintely-don't-exist"sv, Locale::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Locale::region_display_name("en"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "United States"sv);
territory = Locale::region_display_name("en"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Locale::script_display_name("en"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "Latin"sv);
script = Locale::script_display_name("en"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}
TEST_CASE(locale_mappings_fr)
{
auto language = Locale::language_display_name("fr"sv, "en"sv, Locale::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "anglais"sv);
language = Locale::language_display_name("fr"sv, "i-defintely-don't-exist"sv, Locale::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Locale::region_display_name("fr"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "États-Unis"sv);
territory = Locale::region_display_name("fr"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Locale::script_display_name("fr"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "latin"sv);
script = Locale::script_display_name("fr"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}
TEST_CASE(locale_mappings_root)
{
auto language = Locale::language_display_name("und"sv, "en"sv, Locale::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "en"sv);
language = Locale::language_display_name("und"sv, "i-defintely-don't-exist"sv, Locale::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Locale::region_display_name("und"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "US"sv);
territory = Locale::region_display_name("und"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Locale::script_display_name("und"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "Latn"sv);
script = Locale::script_display_name("und"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}

View File

@ -1,6 +1,9 @@
set(TEST_SOURCES set(TEST_SOURCES
TestDisplayNames.cpp
TestEmoji.cpp TestEmoji.cpp
TestIDNA.cpp TestIDNA.cpp
TestLocale.cpp
TestSegmenter.cpp
TestUnicodeCharacterTypes.cpp TestUnicodeCharacterTypes.cpp
TestUnicodeNormalization.cpp TestUnicodeNormalization.cpp
) )

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <LibUnicode/DisplayNames.h>
#include <LibUnicode/Locale.h>
TEST_CASE(locale_mappings_en)
{
auto language = Unicode::language_display_name("en"sv, "en"sv, Unicode::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "English"sv);
language = Unicode::language_display_name("en"sv, "i-defintely-don't-exist"sv, Unicode::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Unicode::region_display_name("en"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "United States"sv);
territory = Unicode::region_display_name("en"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Unicode::script_display_name("en"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "Latin"sv);
script = Unicode::script_display_name("en"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}
TEST_CASE(locale_mappings_fr)
{
auto language = Unicode::language_display_name("fr"sv, "en"sv, Unicode::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "anglais"sv);
language = Unicode::language_display_name("fr"sv, "i-defintely-don't-exist"sv, Unicode::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Unicode::region_display_name("fr"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "États-Unis"sv);
territory = Unicode::region_display_name("fr"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Unicode::script_display_name("fr"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "latin"sv);
script = Unicode::script_display_name("fr"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}
TEST_CASE(locale_mappings_root)
{
auto language = Unicode::language_display_name("und"sv, "en"sv, Unicode::LanguageDisplay::Standard);
EXPECT(language.has_value());
EXPECT_EQ(*language, "en"sv);
language = Unicode::language_display_name("und"sv, "i-defintely-don't-exist"sv, Unicode::LanguageDisplay::Standard);
EXPECT(!language.has_value());
auto territory = Unicode::region_display_name("und"sv, "US"sv);
EXPECT(territory.has_value());
EXPECT_EQ(*territory, "US"sv);
territory = Unicode::region_display_name("und"sv, "i-defintely-don't-exist"sv);
EXPECT(!territory.has_value());
auto script = Unicode::script_display_name("und"sv, "Latn"sv);
EXPECT(script.has_value());
EXPECT_EQ(*script, "Latn"sv);
script = Unicode::script_display_name("und"sv, "i-defintely-don't-exist"sv);
EXPECT(!script.has_value());
}

View File

@ -6,85 +6,85 @@
#include <LibTest/TestCase.h> #include <LibTest/TestCase.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
TEST_CASE(is_unicode_language_subtag) TEST_CASE(is_unicode_language_subtag)
{ {
EXPECT(Locale::is_unicode_language_subtag("aa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aa"sv));
EXPECT(Locale::is_unicode_language_subtag("aaa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aaa"sv));
EXPECT(Locale::is_unicode_language_subtag("aaaaa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aaaaa"sv));
EXPECT(Locale::is_unicode_language_subtag("aaaaaa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aaaaaa"sv));
EXPECT(Locale::is_unicode_language_subtag("aaaaaaa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aaaaaaa"sv));
EXPECT(Locale::is_unicode_language_subtag("aaaaaaaa"sv)); EXPECT(Unicode::is_unicode_language_subtag("aaaaaaaa"sv));
EXPECT(!Locale::is_unicode_language_subtag(""sv)); EXPECT(!Unicode::is_unicode_language_subtag(""sv));
EXPECT(!Locale::is_unicode_language_subtag("a"sv)); EXPECT(!Unicode::is_unicode_language_subtag("a"sv));
EXPECT(!Locale::is_unicode_language_subtag("aaaa"sv)); EXPECT(!Unicode::is_unicode_language_subtag("aaaa"sv));
EXPECT(!Locale::is_unicode_language_subtag("aaaaaaaaa"sv)); EXPECT(!Unicode::is_unicode_language_subtag("aaaaaaaaa"sv));
EXPECT(!Locale::is_unicode_language_subtag("123"sv)); EXPECT(!Unicode::is_unicode_language_subtag("123"sv));
} }
TEST_CASE(is_unicode_script_subtag) TEST_CASE(is_unicode_script_subtag)
{ {
EXPECT(Locale::is_unicode_script_subtag("aaaa"sv)); EXPECT(Unicode::is_unicode_script_subtag("aaaa"sv));
EXPECT(!Locale::is_unicode_script_subtag(""sv)); EXPECT(!Unicode::is_unicode_script_subtag(""sv));
EXPECT(!Locale::is_unicode_script_subtag("a"sv)); EXPECT(!Unicode::is_unicode_script_subtag("a"sv));
EXPECT(!Locale::is_unicode_script_subtag("aa"sv)); EXPECT(!Unicode::is_unicode_script_subtag("aa"sv));
EXPECT(!Locale::is_unicode_script_subtag("aaa"sv)); EXPECT(!Unicode::is_unicode_script_subtag("aaa"sv));
EXPECT(!Locale::is_unicode_script_subtag("aaaaa"sv)); EXPECT(!Unicode::is_unicode_script_subtag("aaaaa"sv));
EXPECT(!Locale::is_unicode_script_subtag("1234"sv)); EXPECT(!Unicode::is_unicode_script_subtag("1234"sv));
} }
TEST_CASE(is_unicode_region_subtag) TEST_CASE(is_unicode_region_subtag)
{ {
EXPECT(Locale::is_unicode_region_subtag("aa"sv)); EXPECT(Unicode::is_unicode_region_subtag("aa"sv));
EXPECT(Locale::is_unicode_region_subtag("123"sv)); EXPECT(Unicode::is_unicode_region_subtag("123"sv));
EXPECT(!Locale::is_unicode_region_subtag(""sv)); EXPECT(!Unicode::is_unicode_region_subtag(""sv));
EXPECT(!Locale::is_unicode_region_subtag("a"sv)); EXPECT(!Unicode::is_unicode_region_subtag("a"sv));
EXPECT(!Locale::is_unicode_region_subtag("aaa"sv)); EXPECT(!Unicode::is_unicode_region_subtag("aaa"sv));
EXPECT(!Locale::is_unicode_region_subtag("12"sv)); EXPECT(!Unicode::is_unicode_region_subtag("12"sv));
EXPECT(!Locale::is_unicode_region_subtag("12a"sv)); EXPECT(!Unicode::is_unicode_region_subtag("12a"sv));
} }
TEST_CASE(is_unicode_variant_subtag) TEST_CASE(is_unicode_variant_subtag)
{ {
EXPECT(Locale::is_unicode_variant_subtag("aaaaa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("aaaaa"sv));
EXPECT(Locale::is_unicode_variant_subtag("aaaaaa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("aaaaaa"sv));
EXPECT(Locale::is_unicode_variant_subtag("aaaaaaa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("aaaaaaa"sv));
EXPECT(Locale::is_unicode_variant_subtag("aaaaaaaa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("aaaaaaaa"sv));
EXPECT(Locale::is_unicode_variant_subtag("1aaa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("1aaa"sv));
EXPECT(Locale::is_unicode_variant_subtag("12aa"sv)); EXPECT(Unicode::is_unicode_variant_subtag("12aa"sv));
EXPECT(Locale::is_unicode_variant_subtag("123a"sv)); EXPECT(Unicode::is_unicode_variant_subtag("123a"sv));
EXPECT(Locale::is_unicode_variant_subtag("1234"sv)); EXPECT(Unicode::is_unicode_variant_subtag("1234"sv));
EXPECT(!Locale::is_unicode_variant_subtag(""sv)); EXPECT(!Unicode::is_unicode_variant_subtag(""sv));
EXPECT(!Locale::is_unicode_variant_subtag("a"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("a"sv));
EXPECT(!Locale::is_unicode_variant_subtag("aa"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("aa"sv));
EXPECT(!Locale::is_unicode_variant_subtag("aaa"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("aaa"sv));
EXPECT(!Locale::is_unicode_variant_subtag("aaaa"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("aaaa"sv));
EXPECT(!Locale::is_unicode_variant_subtag("aaaaaaaaa"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("aaaaaaaaa"sv));
EXPECT(!Locale::is_unicode_variant_subtag("a234"sv)); EXPECT(!Unicode::is_unicode_variant_subtag("a234"sv));
} }
TEST_CASE(is_type_identifier) TEST_CASE(is_type_identifier)
{ {
EXPECT(Locale::is_type_identifier("aaaa"sv)); EXPECT(Unicode::is_type_identifier("aaaa"sv));
EXPECT(Locale::is_type_identifier("aaaa-bbbb"sv)); EXPECT(Unicode::is_type_identifier("aaaa-bbbb"sv));
EXPECT(Locale::is_type_identifier("aaaa-bbbb-cccc"sv)); EXPECT(Unicode::is_type_identifier("aaaa-bbbb-cccc"sv));
EXPECT(Locale::is_type_identifier("1aaa"sv)); EXPECT(Unicode::is_type_identifier("1aaa"sv));
EXPECT(Locale::is_type_identifier("12aa"sv)); EXPECT(Unicode::is_type_identifier("12aa"sv));
EXPECT(Locale::is_type_identifier("123a"sv)); EXPECT(Unicode::is_type_identifier("123a"sv));
EXPECT(Locale::is_type_identifier("1234"sv)); EXPECT(Unicode::is_type_identifier("1234"sv));
EXPECT(!Locale::is_type_identifier(""sv)); EXPECT(!Unicode::is_type_identifier(""sv));
EXPECT(!Locale::is_type_identifier("a"sv)); EXPECT(!Unicode::is_type_identifier("a"sv));
EXPECT(!Locale::is_type_identifier("aa"sv)); EXPECT(!Unicode::is_type_identifier("aa"sv));
EXPECT(!Locale::is_type_identifier("aaaaaaaaa"sv)); EXPECT(!Unicode::is_type_identifier("aaaaaaaaa"sv));
EXPECT(!Locale::is_type_identifier("aaaa-"sv)); EXPECT(!Unicode::is_type_identifier("aaaa-"sv));
} }
template<typename LHS, typename RHS> template<typename LHS, typename RHS>
@ -104,11 +104,11 @@ template<typename LHS, typename RHS>
TEST_CASE(parse_unicode_locale_id) TEST_CASE(parse_unicode_locale_id)
{ {
auto fail = [](StringView locale) { auto fail = [](StringView locale) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
EXPECT(!locale_id.has_value()); EXPECT(!locale_id.has_value());
}; };
auto pass = [](StringView locale, Optional<StringView> expected_language, Optional<StringView> expected_script, Optional<StringView> expected_region, Vector<StringView> expected_variants) { auto pass = [](StringView locale, Optional<StringView> expected_language, Optional<StringView> expected_script, Optional<StringView> expected_region, Vector<StringView> expected_variants) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
EXPECT_EQ(locale_id->language_id.language, expected_language); EXPECT_EQ(locale_id->language_id.language, expected_language);
@ -145,15 +145,15 @@ TEST_CASE(parse_unicode_locale_id_with_unicode_locale_extension)
}; };
auto fail = [](StringView locale) { auto fail = [](StringView locale) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
EXPECT(!locale_id.has_value()); EXPECT(!locale_id.has_value());
}; };
auto pass = [](StringView locale, LocaleExtension const& expected_extension) { auto pass = [](StringView locale, LocaleExtension const& expected_extension) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
EXPECT_EQ(locale_id->extensions.size(), 1u); EXPECT_EQ(locale_id->extensions.size(), 1u);
auto const& actual_extension = locale_id->extensions[0].get<Locale::LocaleExtension>(); auto const& actual_extension = locale_id->extensions[0].get<Unicode::LocaleExtension>();
EXPECT(compare_vectors(actual_extension.attributes, expected_extension.attributes)); EXPECT(compare_vectors(actual_extension.attributes, expected_extension.attributes));
EXPECT_EQ(actual_extension.keywords.size(), expected_extension.keywords.size()); EXPECT_EQ(actual_extension.keywords.size(), expected_extension.keywords.size());
@ -209,15 +209,15 @@ TEST_CASE(parse_unicode_locale_id_with_transformed_extension)
}; };
auto fail = [](StringView locale) { auto fail = [](StringView locale) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
EXPECT(!locale_id.has_value()); EXPECT(!locale_id.has_value());
}; };
auto pass = [](StringView locale, TransformedExtension const& expected_extension) { auto pass = [](StringView locale, TransformedExtension const& expected_extension) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
EXPECT_EQ(locale_id->extensions.size(), 1u); EXPECT_EQ(locale_id->extensions.size(), 1u);
auto const& actual_extension = locale_id->extensions[0].get<Locale::TransformedExtension>(); auto const& actual_extension = locale_id->extensions[0].get<Unicode::TransformedExtension>();
VERIFY(actual_extension.language.has_value() == expected_extension.language.has_value()); VERIFY(actual_extension.language.has_value() == expected_extension.language.has_value());
if (actual_extension.language.has_value()) { if (actual_extension.language.has_value()) {
@ -280,15 +280,15 @@ TEST_CASE(parse_unicode_locale_id_with_other_extension)
}; };
auto fail = [](StringView locale) { auto fail = [](StringView locale) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
EXPECT(!locale_id.has_value()); EXPECT(!locale_id.has_value());
}; };
auto pass = [](StringView locale, OtherExtension const& expected_extension) { auto pass = [](StringView locale, OtherExtension const& expected_extension) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
EXPECT_EQ(locale_id->extensions.size(), 1u); EXPECT_EQ(locale_id->extensions.size(), 1u);
auto const& actual_extension = locale_id->extensions[0].get<Locale::OtherExtension>(); auto const& actual_extension = locale_id->extensions[0].get<Unicode::OtherExtension>();
EXPECT_EQ(actual_extension.key, expected_extension.key); EXPECT_EQ(actual_extension.key, expected_extension.key);
EXPECT_EQ(actual_extension.value, expected_extension.value); EXPECT_EQ(actual_extension.value, expected_extension.value);
}; };
@ -314,11 +314,11 @@ TEST_CASE(parse_unicode_locale_id_with_other_extension)
TEST_CASE(parse_unicode_locale_id_with_private_use_extension) TEST_CASE(parse_unicode_locale_id_with_private_use_extension)
{ {
auto fail = [](StringView locale) { auto fail = [](StringView locale) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
EXPECT(!locale_id.has_value()); EXPECT(!locale_id.has_value());
}; };
auto pass = [](StringView locale, Vector<StringView> const& expected_extension) { auto pass = [](StringView locale, Vector<StringView> const& expected_extension) {
auto locale_id = Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
EXPECT(compare_vectors(locale_id->private_use_extensions, expected_extension)); EXPECT(compare_vectors(locale_id->private_use_extensions, expected_extension));
}; };
@ -338,7 +338,7 @@ TEST_CASE(parse_unicode_locale_id_with_private_use_extension)
TEST_CASE(canonicalize_unicode_locale_id) TEST_CASE(canonicalize_unicode_locale_id)
{ {
auto test = [](StringView locale, StringView expected_canonical_locale) { auto test = [](StringView locale, StringView expected_canonical_locale) {
auto canonical_locale = Locale::canonicalize_unicode_locale_id(locale); auto canonical_locale = Unicode::canonicalize_unicode_locale_id(locale);
EXPECT_EQ(canonical_locale, expected_canonical_locale); EXPECT_EQ(canonical_locale, expected_canonical_locale);
}; };
@ -510,8 +510,8 @@ TEST_CASE(canonicalize_unicode_locale_id)
TEST_CASE(supports_locale_aliases) TEST_CASE(supports_locale_aliases)
{ {
EXPECT(Locale::is_locale_available("zh"sv)); EXPECT(Unicode::is_locale_available("zh"sv));
EXPECT(Locale::is_locale_available("zh-Hant"sv)); EXPECT(Unicode::is_locale_available("zh-Hant"sv));
EXPECT(Locale::is_locale_available("zh-TW"sv)); EXPECT(Unicode::is_locale_available("zh-TW"sv));
EXPECT(Locale::is_locale_available("zh-Hant-TW"sv)); EXPECT(Unicode::is_locale_available("zh-Hant-TW"sv));
} }

View File

@ -10,13 +10,13 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
template<size_t N> template<size_t N>
static void test_grapheme_segmentation(StringView string, size_t const (&expected_boundaries)[N]) static void test_grapheme_segmentation(StringView string, size_t const (&expected_boundaries)[N])
{ {
Vector<size_t> boundaries; Vector<size_t> boundaries;
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
segmenter->for_each_boundary(MUST(String::from_utf8(string)), [&](auto boundary) { segmenter->for_each_boundary(MUST(String::from_utf8(string)), [&](auto boundary) {
boundaries.append(boundary); boundaries.append(boundary);
@ -28,7 +28,7 @@ static void test_grapheme_segmentation(StringView string, size_t const (&expecte
TEST_CASE(grapheme_segmentation) TEST_CASE(grapheme_segmentation)
{ {
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
segmenter->for_each_boundary(String {}, [&](auto i) { segmenter->for_each_boundary(String {}, [&](auto i) {
dbgln("{}", i); dbgln("{}", i);
@ -80,7 +80,7 @@ template<size_t N>
static void test_word_segmentation(StringView string, size_t const (&expected_boundaries)[N]) static void test_word_segmentation(StringView string, size_t const (&expected_boundaries)[N])
{ {
Vector<size_t> boundaries; Vector<size_t> boundaries;
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Word); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Word);
segmenter->for_each_boundary(MUST(String::from_utf8(string)), [&](auto boundary) { segmenter->for_each_boundary(MUST(String::from_utf8(string)), [&](auto boundary) {
boundaries.append(boundary); boundaries.append(boundary);
@ -92,7 +92,7 @@ static void test_word_segmentation(StringView string, size_t const (&expected_bo
TEST_CASE(word_segmentation) TEST_CASE(word_segmentation)
{ {
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Word); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Word);
segmenter->for_each_boundary(String {}, [&](auto) { segmenter->for_each_boundary(String {}, [&](auto) {
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View File

@ -18,7 +18,6 @@ add_subdirectory(LibIPC)
add_subdirectory(LibJS) add_subdirectory(LibJS)
add_subdirectory(LibKeyboard) add_subdirectory(LibKeyboard)
add_subdirectory(LibLine) add_subdirectory(LibLine)
add_subdirectory(LibLocale)
add_subdirectory(LibMain) add_subdirectory(LibMain)
add_subdirectory(LibProtocol) add_subdirectory(LibProtocol)
add_subdirectory(LibRegex) add_subdirectory(LibRegex)

View File

@ -271,10 +271,10 @@ set(SOURCES
) )
serenity_lib(LibJS js) serenity_lib(LibJS js)
target_link_libraries(LibJS PRIVATE LibCore LibCrypto LibFileSystem LibRegex LibSyntax LibUnicode LibTimeZone) target_link_libraries(LibJS PRIVATE LibCore LibCrypto LibFileSystem LibRegex LibSyntax LibTimeZone)
# Link LibLocale publicly to ensure ICU data (which is in libicudata.a) is available in any process using LibJS. # Link LibUnicode publicly to ensure ICU data (which is in libicudata.a) is available in any process using LibJS.
target_link_libraries(LibJS PUBLIC LibLocale) target_link_libraries(LibJS PUBLIC LibUnicode)
# TODO: This is probably also needed on RISC-V. # TODO: This is probably also needed on RISC-V.
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86.*") if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86.*")

View File

@ -740,7 +740,7 @@ ErrorOr<void> print_intl_date_time_format(JS::PrintContext& print_context, JS::I
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.numbering_system()), seen_objects)); TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.numbering_system()), seen_objects));
if (date_time_format.hour_cycle.has_value()) { if (date_time_format.hour_cycle.has_value()) {
TRY(js_out(print_context, "\n hourCycle: ")); TRY(js_out(print_context, "\n hourCycle: "));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), ::Locale::hour_cycle_to_string(*date_time_format.hour_cycle)), seen_objects)); TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), Unicode::hour_cycle_to_string(*date_time_format.hour_cycle)), seen_objects));
} }
TRY(js_out(print_context, "\n timeZone: ")); TRY(js_out(print_context, "\n timeZone: "));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.time_zone()), seen_objects)); TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.time_zone()), seen_objects));
@ -768,7 +768,7 @@ ErrorOr<void> print_intl_date_time_format(JS::PrintContext& print_context, JS::I
if (print_value(print_context, JS::Value(*option), seen_objects).is_error()) if (print_value(print_context, JS::Value(*option), seen_objects).is_error())
return JS::throw_completion(JS::js_null()); return JS::throw_completion(JS::js_null());
} else { } else {
auto name = Locale::calendar_pattern_style_to_string(*option); auto name = Unicode::calendar_pattern_style_to_string(*option);
if (print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), name), seen_objects).is_error()) if (print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), name), seen_objects).is_error())
return JS::throw_completion(JS::js_null()); return JS::throw_completion(JS::js_null());
} }

View File

@ -24,9 +24,9 @@
#include <LibJS/Runtime/Temporal/Instant.h> #include <LibJS/Runtime/Temporal/Instant.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/DisplayNames.h>
#include <LibLocale/Locale.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <LibUnicode/DisplayNames.h>
#include <LibUnicode/Locale.h>
namespace JS { namespace JS {
@ -1156,7 +1156,7 @@ ByteString time_zone_string(double time)
// Most implementations seem to prefer the long-form display name of the time zone. Not super important, but we may as well match that behavior. // Most implementations seem to prefer the long-form display name of the time zone. Not super important, but we may as well match that behavior.
if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::UnixDateTime::from_milliseconds_since_epoch(time)); maybe_offset.has_value()) { if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::UnixDateTime::from_milliseconds_since_epoch(time)); maybe_offset.has_value()) {
if (auto name = Locale::time_zone_display_name(Locale::default_locale(), tz_name, maybe_offset->in_dst, time); name.has_value()) if (auto name = Unicode::time_zone_display_name(Unicode::default_locale(), tz_name, maybe_offset->in_dst, time); name.has_value())
tz_name = name.release_value(); tz_name = name.release_value();
} else { } else {
tz_name = MUST(String::from_utf8(TimeZone::current_time_zone())); tz_name = MUST(String::from_utf8(TimeZone::current_time_zone()));

View File

@ -16,7 +16,7 @@
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h> #include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/UnicodeKeywords.h> #include <LibUnicode/UnicodeKeywords.h>
namespace JS::Intl { namespace JS::Intl {
@ -49,10 +49,10 @@ bool is_structurally_valid_language_tag(StringView locale)
}; };
// 1. Let lowerLocale be the ASCII-lowercase of locale. // 1. Let lowerLocale be the ASCII-lowercase of locale.
// NOTE: LibLocale's parsing is case-insensitive. // NOTE: LibUnicode's parsing is case-insensitive.
// 2. If lowerLocale cannot be matched by the unicode_locale_id Unicode locale nonterminal, return false. // 2. If lowerLocale cannot be matched by the unicode_locale_id Unicode locale nonterminal, return false.
auto locale_id = ::Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
if (!locale_id.has_value()) if (!locale_id.has_value())
return false; return false;
@ -81,9 +81,9 @@ bool is_structurally_valid_language_tag(StringView locale)
// 9. If extensions is not the empty String, then // 9. If extensions is not the empty String, then
for (auto& extension : locale_id->extensions) { for (auto& extension : locale_id->extensions) {
char key = extension.visit( char key = extension.visit(
[](::Locale::LocaleExtension const&) { return 'u'; }, [](Unicode::LocaleExtension const&) { return 'u'; },
[](::Locale::TransformedExtension const&) { return 't'; }, [](Unicode::TransformedExtension const&) { return 't'; },
[](::Locale::OtherExtension const& ext) { return static_cast<char>(to_ascii_lowercase(ext.key)); }); [](Unicode::OtherExtension const& ext) { return static_cast<char>(to_ascii_lowercase(ext.key)); });
// a. If extensions contains any duplicate singleton subtags, return false. // a. If extensions contains any duplicate singleton subtags, return false.
if (unique_keys.set(key) != HashSetResult::InsertedNewEntry) if (unique_keys.set(key) != HashSetResult::InsertedNewEntry)
@ -91,7 +91,7 @@ bool is_structurally_valid_language_tag(StringView locale)
// b. Let transformExtension be the longest substring of extensions matched by the transformed_extensions Unicode // b. Let transformExtension be the longest substring of extensions matched by the transformed_extensions Unicode
// locale nonterminal. If there is no such substring, return true. // locale nonterminal. If there is no such substring, return true.
if (auto* transformed = extension.get_pointer<::Locale::TransformedExtension>()) { if (auto* transformed = extension.get_pointer<Unicode::TransformedExtension>()) {
// c. Assert: The substring of transformExtension from 0 to 3 is "-t-". // c. Assert: The substring of transformExtension from 0 to 3 is "-t-".
// d. Let tPrefix be the substring of transformExtension from 3. // d. Let tPrefix be the substring of transformExtension from 3.
@ -119,7 +119,7 @@ bool is_structurally_valid_language_tag(StringView locale)
// 6.2.3 CanonicalizeUnicodeLocaleId ( locale ), https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid // 6.2.3 CanonicalizeUnicodeLocaleId ( locale ), https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid
String canonicalize_unicode_locale_id(StringView locale) String canonicalize_unicode_locale_id(StringView locale)
{ {
return ::Locale::canonicalize_unicode_locale_id(locale); return Unicode::canonicalize_unicode_locale_id(locale);
} }
// 6.3.1 IsWellFormedCurrencyCode ( currency ), https://tc39.es/ecma402/#sec-iswellformedcurrencycode // 6.3.1 IsWellFormedCurrencyCode ( currency ), https://tc39.es/ecma402/#sec-iswellformedcurrencycode
@ -267,15 +267,15 @@ Optional<MatchedLocale> lookup_matching_locale_by_prefix(ReadonlySpan<String> re
{ {
// 1. For each element locale of requestedLocales, do // 1. For each element locale of requestedLocales, do
for (auto locale : requested_locales) { for (auto locale : requested_locales) {
auto locale_id = ::Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
// a. Let extension be empty. // a. Let extension be empty.
Optional<::Locale::Extension> extension; Optional<Unicode::Extension> extension;
String locale_without_extension; String locale_without_extension;
// b. If locale contains a Unicode locale extension sequence, then // b. If locale contains a Unicode locale extension sequence, then
if (auto extensions = locale_id->remove_extension_type<::Locale::LocaleExtension>(); !extensions.is_empty()) { if (auto extensions = locale_id->remove_extension_type<Unicode::LocaleExtension>(); !extensions.is_empty()) {
VERIFY(extensions.size() == 1); VERIFY(extensions.size() == 1);
// i. Set extension to the Unicode locale extension sequence of locale. // i. Set extension to the Unicode locale extension sequence of locale.
@ -291,7 +291,7 @@ Optional<MatchedLocale> lookup_matching_locale_by_prefix(ReadonlySpan<String> re
// d. Repeat, while prefix is not the empty String, // d. Repeat, while prefix is not the empty String,
while (!prefix.is_empty()) { while (!prefix.is_empty()) {
// i. If availableLocales contains prefix, return the Record { [[locale]]: prefix, [[extension]]: extension }. // i. If availableLocales contains prefix, return the Record { [[locale]]: prefix, [[extension]]: extension }.
if (::Locale::is_locale_available(prefix)) if (Unicode::is_locale_available(prefix))
return MatchedLocale { MUST(String::from_utf8(prefix)), move(extension) }; return MatchedLocale { MUST(String::from_utf8(prefix)), move(extension) };
// ii. If prefix contains "-" (code unit 0x002D HYPHEN-MINUS), let pos be the index into prefix of the last // ii. If prefix contains "-" (code unit 0x002D HYPHEN-MINUS), let pos be the index into prefix of the last
@ -322,13 +322,13 @@ Optional<MatchedLocale> lookup_matching_locale_by_best_fit(ReadonlySpan<String>
} }
// 9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, attributes, keywords ), https://tc39.es/ecma402/#sec-insert-unicode-extension-and-canonicalize // 9.2.6 InsertUnicodeExtensionAndCanonicalize ( locale, attributes, keywords ), https://tc39.es/ecma402/#sec-insert-unicode-extension-and-canonicalize
String insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale, Vector<String> attributes, Vector<::Locale::Keyword> keywords) String insert_unicode_extension_and_canonicalize(Unicode::LocaleID locale, Vector<String> attributes, Vector<Unicode::Keyword> keywords)
{ {
// Note: This implementation differs from the spec in how the extension is inserted. The spec assumes // Note: This implementation differs from the spec in how the extension is inserted. The spec assumes
// the input to this method is a string, and is written such that operations are performed on parts // the input to this method is a string, and is written such that operations are performed on parts
// of that string. LibLocale gives us the parsed locale in a structure, so we can mutate that // of that string. LibUnicode gives us the parsed locale in a structure, so we can mutate that
// structure directly. // structure directly.
locale.extensions.append(::Locale::LocaleExtension { move(attributes), move(keywords) }); locale.extensions.append(Unicode::LocaleExtension { move(attributes), move(keywords) });
// 10. Return CanonicalizeUnicodeLocaleId(newLocale). // 10. Return CanonicalizeUnicodeLocaleId(newLocale).
return JS::Intl::canonicalize_unicode_locale_id(locale.to_string()); return JS::Intl::canonicalize_unicode_locale_id(locale.to_string());
@ -356,7 +356,7 @@ static auto& find_key_in_value(T& value, StringView key)
static Vector<LocaleKey> available_keyword_values(StringView locale, StringView key) static Vector<LocaleKey> available_keyword_values(StringView locale, StringView key)
{ {
auto key_locale_data = ::Locale::available_keyword_values(locale, key); auto key_locale_data = Unicode::available_keyword_values(locale, key);
Vector<LocaleKey> result; Vector<LocaleKey> result;
result.ensure_capacity(key_locale_data.size()); result.ensure_capacity(key_locale_data.size());
@ -396,7 +396,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
// 4. If r is undefined, set r to the Record { [[locale]]: DefaultLocale(), [[extension]]: empty }. // 4. If r is undefined, set r to the Record { [[locale]]: DefaultLocale(), [[extension]]: empty }.
if (!matcher_result.has_value()) if (!matcher_result.has_value())
matcher_result = MatchedLocale { MUST(String::from_utf8(::Locale::default_locale())), {} }; matcher_result = MatchedLocale { MUST(String::from_utf8(Unicode::default_locale())), {} };
// 5. Let foundLocale be r.[[locale]]. // 5. Let foundLocale be r.[[locale]].
auto found_locale = move(matcher_result->locale); auto found_locale = move(matcher_result->locale);
@ -408,12 +408,12 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
// 9. Set result.[[LocaleData]] to foundLocaleData. // 9. Set result.[[LocaleData]] to foundLocaleData.
ResolvedLocale result {}; ResolvedLocale result {};
Vector<::Locale::Keyword> keywords; Vector<Unicode::Keyword> keywords;
// 10. If r.[[extension]] is not empty, then // 10. If r.[[extension]] is not empty, then
if (matcher_result->extension.has_value()) { if (matcher_result->extension.has_value()) {
// a. Let components be UnicodeExtensionComponents(r.[[extension]]). // a. Let components be UnicodeExtensionComponents(r.[[extension]]).
auto& components = matcher_result->extension->get<::Locale::LocaleExtension>(); auto& components = matcher_result->extension->get<Unicode::LocaleExtension>();
// b. Let keywords be components.[[Keywords]]. // b. Let keywords be components.[[Keywords]].
keywords = move(components.keywords); keywords = move(components.keywords);
@ -422,7 +422,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
// a. Let keywords be a new empty List. // a. Let keywords be a new empty List.
// 12. Let supportedKeywords be a new empty List. // 12. Let supportedKeywords be a new empty List.
Vector<::Locale::Keyword> supported_keywords; Vector<Unicode::Keyword> supported_keywords;
// 13. For each element key of relevantExtensionKeys, do // 13. For each element key of relevantExtensionKeys, do
for (auto const& key : relevant_extension_keys) { for (auto const& key : relevant_extension_keys) {
@ -435,7 +435,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
auto value = key_locale_data[0]; auto value = key_locale_data[0];
// e. Let supportedKeyword be empty. // e. Let supportedKeyword be empty.
Optional<::Locale::Keyword> supported_keyword; Optional<Unicode::Keyword> supported_keyword;
// f. If keywords contains an element whose [[Key]] is key, then // f. If keywords contains an element whose [[Key]] is key, then
if (auto entry = keywords.find_if([&](auto const& entry) { return entry.key == key; }); entry != keywords.end()) { if (auto entry = keywords.find_if([&](auto const& entry) { return entry.key == key; }); entry != keywords.end()) {
@ -451,7 +451,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
value = move(requested_value); value = move(requested_value);
// b. Set supportedKeyword to the Record { [[Key]]: key, [[Value]]: value }. // b. Set supportedKeyword to the Record { [[Key]]: key, [[Value]]: value }.
supported_keyword = ::Locale::Keyword { MUST(String::from_utf8(key)), move(entry->value) }; supported_keyword = Unicode::Keyword { MUST(String::from_utf8(key)), move(entry->value) };
} }
} }
// iv. Else if keyLocaleData contains "true", then // iv. Else if keyLocaleData contains "true", then
@ -460,7 +460,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
value = true_string; value = true_string;
// 2. Set supportedKeyword to the Record { [[Key]]: key, [[Value]]: "" }. // 2. Set supportedKeyword to the Record { [[Key]]: key, [[Value]]: "" }.
supported_keyword = ::Locale::Keyword { MUST(String::from_utf8(key)), {} }; supported_keyword = Unicode::Keyword { MUST(String::from_utf8(key)), {} };
} }
} }
@ -476,7 +476,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
// https://github.com/tc39/ecma402/pull/846#discussion_r1428263375 // https://github.com/tc39/ecma402/pull/846#discussion_r1428263375
// ii. Set optionsValue to CanonicalizeUValue(ukey, optionsValue). // ii. Set optionsValue to CanonicalizeUValue(ukey, optionsValue).
*options_string = ::Locale::canonicalize_unicode_extension_values(key, *options_string); *options_string = Unicode::canonicalize_unicode_extension_values(key, *options_string);
// iii. If optionsValue is the empty String, then // iii. If optionsValue is the empty String, then
if (options_string->is_empty()) { if (options_string->is_empty()) {
@ -504,7 +504,7 @@ ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOpti
// 14. If supportedKeywords is not empty, then // 14. If supportedKeywords is not empty, then
if (!supported_keywords.is_empty()) { if (!supported_keywords.is_empty()) {
auto locale_id = ::Locale::parse_unicode_locale_id(found_locale); auto locale_id = Unicode::parse_unicode_locale_id(found_locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
// a. Let supportedAttributes be a new empty List. // a. Let supportedAttributes be a new empty List.
@ -535,11 +535,11 @@ ThrowCompletionOr<Array*> filter_locales(VM& vm, ReadonlySpan<String> requested_
// 4. For each element locale of requestedLocales, do // 4. For each element locale of requestedLocales, do
for (auto const& locale : requested_locales) { for (auto const& locale : requested_locales) {
auto locale_id = ::Locale::parse_unicode_locale_id(locale); auto locale_id = Unicode::parse_unicode_locale_id(locale);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
// a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed. // a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed.
locale_id->remove_extension_type<::Locale::LocaleExtension>(); locale_id->remove_extension_type<Unicode::LocaleExtension>();
auto no_extensions_locale = locale_id->to_string(); auto no_extensions_locale = locale_id->to_string();
Optional<MatchedLocale> match; Optional<MatchedLocale> match;

View File

@ -14,7 +14,7 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h> #include <LibJS/Runtime/Temporal/AbstractOperations.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -33,7 +33,7 @@ struct LocaleOptions {
struct MatchedLocale { struct MatchedLocale {
String locale; String locale;
Optional<::Locale::Extension> extension; Optional<Unicode::Extension> extension;
}; };
struct ResolvedLocale { struct ResolvedLocale {
@ -55,7 +55,7 @@ bool is_well_formed_unit_identifier(StringView unit_identifier);
ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM&, Value locales); ThrowCompletionOr<Vector<String>> canonicalize_locale_list(VM&, Value locales);
Optional<MatchedLocale> lookup_matching_locale_by_prefix(ReadonlySpan<String> requested_locales); Optional<MatchedLocale> lookup_matching_locale_by_prefix(ReadonlySpan<String> requested_locales);
Optional<MatchedLocale> lookup_matching_locale_by_best_fit(ReadonlySpan<String> requested_locales); Optional<MatchedLocale> lookup_matching_locale_by_best_fit(ReadonlySpan<String> requested_locales);
String insert_unicode_extension_and_canonicalize(::Locale::LocaleID locale_id, Vector<String> attributes, Vector<::Locale::Keyword> keywords); String insert_unicode_extension_and_canonicalize(Unicode::LocaleID locale_id, Vector<String> attributes, Vector<Unicode::Keyword> keywords);
ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys); ResolvedLocale resolve_locale(ReadonlySpan<String> requested_locales, LocaleOptions const& options, ReadonlySpan<StringView> relevant_extension_keys);
ThrowCompletionOr<Array*> filter_locales(VM& vm, ReadonlySpan<String> requested_locales, Value options); ThrowCompletionOr<Array*> filter_locales(VM& vm, ReadonlySpan<String> requested_locales, Value options);
ThrowCompletionOr<Object*> coerce_options_to_object(VM&, Value options); ThrowCompletionOr<Object*> coerce_options_to_object(VM&, Value options);

View File

@ -10,7 +10,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/Collator.h> #include <LibJS/Runtime/Intl/Collator.h>
#include <LibJS/Runtime/Intl/CollatorConstructor.h> #include <LibJS/Runtime/Intl/CollatorConstructor.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -51,7 +51,7 @@ static ThrowCompletionOr<NonnullGCPtr<Collator>> initialize_collator(VM& vm, Col
// 11. If collation is not undefined, then // 11. If collation is not undefined, then
if (!collation.is_undefined()) { if (!collation.is_undefined()) {
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(collation.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(collation.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, collation, "collation"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, collation, "collation"sv);
// 12. Set opt.[[co]] to collation. // 12. Set opt.[[co]] to collation.

View File

@ -27,7 +27,7 @@ void DateTimeFormat::visit_edges(Cell::Visitor& visitor)
} }
// 11.5.5 FormatDateTimePattern ( dateTimeFormat, patternParts, x, rangeFormatOptions ), https://tc39.es/ecma402/#sec-formatdatetimepattern // 11.5.5 FormatDateTimePattern ( dateTimeFormat, patternParts, x, rangeFormatOptions ), https://tc39.es/ecma402/#sec-formatdatetimepattern
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, double time) ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, double time)
{ {
// 1. Let x be TimeClip(x). // 1. Let x be TimeClip(x).
time = time_clip(time); time = time_clip(time);
@ -40,7 +40,7 @@ ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> format_date_time_
} }
// 11.5.6 PartitionDateTimePattern ( dateTimeFormat, x ), https://tc39.es/ecma402/#sec-partitiondatetimepattern // 11.5.6 PartitionDateTimePattern ( dateTimeFormat, x ), https://tc39.es/ecma402/#sec-partitiondatetimepattern
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> partition_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, double time) ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> partition_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, double time)
{ {
// 1. Let patternParts be PartitionPattern(dateTimeFormat.[[Pattern]]). // 1. Let patternParts be PartitionPattern(dateTimeFormat.[[Pattern]]).
// 2. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined). // 2. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined).
@ -107,7 +107,7 @@ ThrowCompletionOr<NonnullGCPtr<Array>> format_date_time_to_parts(VM& vm, DateTim
} }
// 11.5.9 PartitionDateTimeRangePattern ( dateTimeFormat, x, y ), https://tc39.es/ecma402/#sec-partitiondatetimerangepattern // 11.5.9 PartitionDateTimeRangePattern ( dateTimeFormat, x, y ), https://tc39.es/ecma402/#sec-partitiondatetimerangepattern
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> partition_date_time_range_pattern(VM& vm, DateTimeFormat& date_time_format, double start, double end) ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> partition_date_time_range_pattern(VM& vm, DateTimeFormat& date_time_format, double start, double end)
{ {
// 1. Let x be TimeClip(x). // 1. Let x be TimeClip(x).
start = time_clip(start); start = time_clip(start);

View File

@ -14,17 +14,17 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>
#include <LibLocale/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
namespace JS::Intl { namespace JS::Intl {
class DateTimeFormat final class DateTimeFormat final
: public Object : public Object
, public ::Locale::CalendarPattern { , public Unicode::CalendarPattern {
JS_OBJECT(DateTimeFormat, Object); JS_OBJECT(DateTimeFormat, Object);
JS_DECLARE_ALLOCATOR(DateTimeFormat); JS_DECLARE_ALLOCATOR(DateTimeFormat);
using Patterns = ::Locale::CalendarPattern; using Patterns = Unicode::CalendarPattern;
public: public:
static constexpr auto relevant_extension_keys() static constexpr auto relevant_extension_keys()
@ -49,48 +49,48 @@ public:
void set_time_zone(String time_zone) { m_time_zone = move(time_zone); } void set_time_zone(String time_zone) { m_time_zone = move(time_zone); }
bool has_date_style() const { return m_date_style.has_value(); } bool has_date_style() const { return m_date_style.has_value(); }
Optional<::Locale::DateTimeStyle> const& date_style() const { return m_date_style; } Optional<Unicode::DateTimeStyle> const& date_style() const { return m_date_style; }
StringView date_style_string() const { return ::Locale::date_time_style_to_string(*m_date_style); } StringView date_style_string() const { return Unicode::date_time_style_to_string(*m_date_style); }
void set_date_style(StringView style) { m_date_style = ::Locale::date_time_style_from_string(style); } void set_date_style(StringView style) { m_date_style = Unicode::date_time_style_from_string(style); }
bool has_time_style() const { return m_time_style.has_value(); } bool has_time_style() const { return m_time_style.has_value(); }
Optional<::Locale::DateTimeStyle> const& time_style() const { return m_time_style; } Optional<Unicode::DateTimeStyle> const& time_style() const { return m_time_style; }
StringView time_style_string() const { return ::Locale::date_time_style_to_string(*m_time_style); } StringView time_style_string() const { return Unicode::date_time_style_to_string(*m_time_style); }
void set_time_style(StringView style) { m_time_style = ::Locale::date_time_style_from_string(style); } void set_time_style(StringView style) { m_time_style = Unicode::date_time_style_from_string(style); }
NativeFunction* bound_format() const { return m_bound_format; } NativeFunction* bound_format() const { return m_bound_format; }
void set_bound_format(NativeFunction* bound_format) { m_bound_format = bound_format; } void set_bound_format(NativeFunction* bound_format) { m_bound_format = bound_format; }
::Locale::DateTimeFormat const& formatter() const { return *m_formatter; } Unicode::DateTimeFormat const& formatter() const { return *m_formatter; }
void set_formatter(NonnullOwnPtr<::Locale::DateTimeFormat> formatter) { m_formatter = move(formatter); } void set_formatter(NonnullOwnPtr<Unicode::DateTimeFormat> formatter) { m_formatter = move(formatter); }
private: private:
DateTimeFormat(Object& prototype); DateTimeFormat(Object& prototype);
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
String m_calendar; // [[Calendar]] String m_calendar; // [[Calendar]]
String m_numbering_system; // [[NumberingSystem]] String m_numbering_system; // [[NumberingSystem]]
String m_time_zone; // [[TimeZone]] String m_time_zone; // [[TimeZone]]
Optional<::Locale::DateTimeStyle> m_date_style; // [[DateStyle]] Optional<Unicode::DateTimeStyle> m_date_style; // [[DateStyle]]
Optional<::Locale::DateTimeStyle> m_time_style; // [[TimeStyle]] Optional<Unicode::DateTimeStyle> m_time_style; // [[TimeStyle]]
GCPtr<NativeFunction> m_bound_format; // [[BoundFormat]] GCPtr<NativeFunction> m_bound_format; // [[BoundFormat]]
// Non-standard. Stores the ICU date-time formatter for the Intl object's formatting options. // Non-standard. Stores the ICU date-time formatter for the Intl object's formatting options.
OwnPtr<::Locale::DateTimeFormat> m_formatter; OwnPtr<Unicode::DateTimeFormat> m_formatter;
}; };
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> format_date_time_pattern(VM&, DateTimeFormat&, double time); ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> format_date_time_pattern(VM&, DateTimeFormat&, double time);
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> partition_date_time_pattern(VM&, DateTimeFormat&, double time); ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> partition_date_time_pattern(VM&, DateTimeFormat&, double time);
ThrowCompletionOr<String> format_date_time(VM&, DateTimeFormat&, double time); ThrowCompletionOr<String> format_date_time(VM&, DateTimeFormat&, double time);
ThrowCompletionOr<NonnullGCPtr<Array>> format_date_time_to_parts(VM&, DateTimeFormat&, double time); ThrowCompletionOr<NonnullGCPtr<Array>> format_date_time_to_parts(VM&, DateTimeFormat&, double time);
ThrowCompletionOr<Vector<::Locale::DateTimeFormat::Partition>> partition_date_time_range_pattern(VM&, DateTimeFormat&, double start, double end); ThrowCompletionOr<Vector<Unicode::DateTimeFormat::Partition>> partition_date_time_range_pattern(VM&, DateTimeFormat&, double start, double end);
ThrowCompletionOr<String> format_date_time_range(VM&, DateTimeFormat&, double start, double end); ThrowCompletionOr<String> format_date_time_range(VM&, DateTimeFormat&, double start, double end);
ThrowCompletionOr<NonnullGCPtr<Array>> format_date_time_range_to_parts(VM&, DateTimeFormat&, double start, double end); ThrowCompletionOr<NonnullGCPtr<Array>> format_date_time_range_to_parts(VM&, DateTimeFormat&, double start, double end);
template<typename Callback> template<typename Callback>
ThrowCompletionOr<void> for_each_calendar_field(VM& vm, ::Locale::CalendarPattern& pattern, Callback&& callback) ThrowCompletionOr<void> for_each_calendar_field(VM& vm, Unicode::CalendarPattern& pattern, Callback&& callback)
{ {
constexpr auto narrow_short_long = AK::Array { "narrow"sv, "short"sv, "long"sv }; constexpr auto narrow_short_long = AK::Array { "narrow"sv, "short"sv, "long"sv };
constexpr auto two_digit_numeric = AK::Array { "2-digit"sv, "numeric"sv }; constexpr auto two_digit_numeric = AK::Array { "2-digit"sv, "numeric"sv };

View File

@ -12,8 +12,8 @@
#include <LibJS/Runtime/Intl/DateTimeFormat.h> #include <LibJS/Runtime/Intl/DateTimeFormat.h>
#include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h> #include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h>
#include <LibJS/Runtime/Temporal/TimeZone.h> #include <LibJS/Runtime/Temporal/TimeZone.h>
#include <LibLocale/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -108,7 +108,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 8. If calendar is not undefined, then // 8. If calendar is not undefined, then
if (!calendar.is_undefined()) { if (!calendar.is_undefined()) {
// a. If calendar cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception. // a. If calendar cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(calendar.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(calendar.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, calendar, "calendar"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, calendar, "calendar"sv);
} }
@ -121,7 +121,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 11. If numberingSystem is not undefined, then // 11. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) { if (!numbering_system.is_undefined()) {
// a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception. // a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(numbering_system.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
} }
@ -162,7 +162,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 23. Let dataLocale be r.[[dataLocale]]. // 23. Let dataLocale be r.[[dataLocale]].
// 24. Let dataLocaleData be localeData.[[<dataLocale>]]. // 24. Let dataLocaleData be localeData.[[<dataLocale>]].
Optional<::Locale::HourCycle> hour_cycle_value; Optional<Unicode::HourCycle> hour_cycle_value;
Optional<bool> hour12_value; Optional<bool> hour12_value;
// 25. If hour12 is true, then // 25. If hour12 is true, then
@ -170,7 +170,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 26. Else if hour12 is false, then // 26. Else if hour12 is false, then
// a. Let hc be dataLocaleData.[[hourCycle24]]. // a. Let hc be dataLocaleData.[[hourCycle24]].
if (hour12.is_boolean()) { if (hour12.is_boolean()) {
// NOTE: We let LibLocale figure out the appropriate hour cycle. // NOTE: We let LibUnicode figure out the appropriate hour cycle.
hour12_value = hour12.as_bool(); hour12_value = hour12.as_bool();
} }
// 27. Else, // 27. Else,
@ -180,11 +180,11 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// b. Let hc be r.[[hc]]. // b. Let hc be r.[[hc]].
if (auto* resolved_hour_cycle = result.hc.get_pointer<String>()) if (auto* resolved_hour_cycle = result.hc.get_pointer<String>())
hour_cycle_value = ::Locale::hour_cycle_from_string(*resolved_hour_cycle); hour_cycle_value = Unicode::hour_cycle_from_string(*resolved_hour_cycle);
// c. If hc is null, set hc to dataLocaleData.[[hourCycle]]. // c. If hc is null, set hc to dataLocaleData.[[hourCycle]].
if (!hour_cycle_value.has_value()) if (!hour_cycle_value.has_value())
hour_cycle_value = ::Locale::default_hour_cycle(date_time_format->locale()); hour_cycle_value = Unicode::default_hour_cycle(date_time_format->locale());
} }
// 28. Set dateTimeFormat.[[HourCycle]] to hc. // 28. Set dateTimeFormat.[[HourCycle]] to hc.
@ -250,7 +250,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
time_zone = MUST(String::formatted("GMT{}", time_zone)); time_zone = MUST(String::formatted("GMT{}", time_zone));
// 36. Let formatOptions be a new Record. // 36. Let formatOptions be a new Record.
::Locale::CalendarPattern format_options {}; Unicode::CalendarPattern format_options {};
// 37. Set formatOptions.[[hourCycle]] to hc. // 37. Set formatOptions.[[hourCycle]] to hc.
format_options.hour_cycle = hour_cycle_value; format_options.hour_cycle = hour_cycle_value;
@ -288,7 +288,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// d. Set formatOptions.[[<prop>]] to value. // d. Set formatOptions.[[<prop>]] to value.
if (!value.is_undefined()) { if (!value.is_undefined()) {
option = ::Locale::calendar_pattern_style_from_string(value.as_string().utf8_string_view()); option = Unicode::calendar_pattern_style_from_string(value.as_string().utf8_string_view());
// e. If value is not undefined, then // e. If value is not undefined, then
// i. Set hasExplicitFormatComponents to true. // i. Set hasExplicitFormatComponents to true.
@ -338,7 +338,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// d. Let styles be dataLocaleData.[[styles]].[[<resolvedCalendar>]]. // d. Let styles be dataLocaleData.[[styles]].[[<resolvedCalendar>]].
// e. Let bestFormat be DateTimeStyleFormat(dateStyle, timeStyle, styles). // e. Let bestFormat be DateTimeStyleFormat(dateStyle, timeStyle, styles).
auto formatter = ::Locale::DateTimeFormat::create_for_date_and_time_style( auto formatter = Unicode::DateTimeFormat::create_for_date_and_time_style(
date_time_format->locale(), date_time_format->locale(),
time_zone, time_zone,
format_options.hour_cycle, format_options.hour_cycle,
@ -390,7 +390,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// i. For each property name prop of « "year", "month", "day" », do // i. For each property name prop of « "year", "month", "day" », do
auto set_property_value = [&](auto& value) { auto set_property_value = [&](auto& value) {
// 1. Set formatOptions.[[<prop>]] to "numeric". // 1. Set formatOptions.[[<prop>]] to "numeric".
value = ::Locale::CalendarPatternStyle::Numeric; value = Unicode::CalendarPatternStyle::Numeric;
}; };
set_property_value(format_options.year); set_property_value(format_options.year);
@ -403,7 +403,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// i. For each property name prop of « "hour", "minute", "second" », do // i. For each property name prop of « "hour", "minute", "second" », do
auto set_property_value = [&](auto& value) { auto set_property_value = [&](auto& value) {
// 1. Set formatOptions.[[<prop>]] to "numeric". // 1. Set formatOptions.[[<prop>]] to "numeric".
value = ::Locale::CalendarPatternStyle::Numeric; value = Unicode::CalendarPatternStyle::Numeric;
}; };
set_property_value(format_options.hour); set_property_value(format_options.hour);
@ -416,7 +416,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// i. Let bestFormat be BasicFormatMatcher(formatOptions, formats). // i. Let bestFormat be BasicFormatMatcher(formatOptions, formats).
// h. Else, // h. Else,
// i. Let bestFormat be BestFitFormatMatcher(formatOptions, formats). // i. Let bestFormat be BestFitFormatMatcher(formatOptions, formats).
auto formatter = ::Locale::DateTimeFormat::create_for_pattern_options( auto formatter = Unicode::DateTimeFormat::create_for_pattern_options(
date_time_format->locale(), date_time_format->locale(),
time_zone, time_zone,
format_options); format_options);

View File

@ -10,7 +10,7 @@
#include <LibJS/Runtime/Intl/DateTimeFormatFunction.h> #include <LibJS/Runtime/Intl/DateTimeFormatFunction.h>
#include <LibJS/Runtime/Intl/DateTimeFormatPrototype.h> #include <LibJS/Runtime/Intl/DateTimeFormatPrototype.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -180,15 +180,15 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
MUST(options->create_data_property_or_throw(vm.names.timeZone, PrimitiveString::create(vm, date_time_format->time_zone()))); MUST(options->create_data_property_or_throw(vm.names.timeZone, PrimitiveString::create(vm, date_time_format->time_zone())));
if (date_time_format->hour_cycle.has_value()) { if (date_time_format->hour_cycle.has_value()) {
MUST(options->create_data_property_or_throw(vm.names.hourCycle, PrimitiveString::create(vm, ::Locale::hour_cycle_to_string(*date_time_format->hour_cycle)))); MUST(options->create_data_property_or_throw(vm.names.hourCycle, PrimitiveString::create(vm, Unicode::hour_cycle_to_string(*date_time_format->hour_cycle))));
switch (*date_time_format->hour_cycle) { switch (*date_time_format->hour_cycle) {
case ::Locale::HourCycle::H11: case Unicode::HourCycle::H11:
case ::Locale::HourCycle::H12: case Unicode::HourCycle::H12:
MUST(options->create_data_property_or_throw(vm.names.hour12, Value(true))); MUST(options->create_data_property_or_throw(vm.names.hour12, Value(true)));
break; break;
case ::Locale::HourCycle::H23: case Unicode::HourCycle::H23:
case ::Locale::HourCycle::H24: case Unicode::HourCycle::H24:
MUST(options->create_data_property_or_throw(vm.names.hour12, Value(false))); MUST(options->create_data_property_or_throw(vm.names.hour12, Value(false)));
break; break;
} }
@ -204,7 +204,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
if constexpr (IsIntegral<ValueType>) { if constexpr (IsIntegral<ValueType>) {
MUST(options->create_data_property_or_throw(property, Value(*option))); MUST(options->create_data_property_or_throw(property, Value(*option)));
} else { } else {
auto name = ::Locale::calendar_pattern_style_to_string(*option); auto name = Unicode::calendar_pattern_style_to_string(*option);
MUST(options->create_data_property_or_throw(property, PrimitiveString::create(vm, name))); MUST(options->create_data_property_or_throw(property, PrimitiveString::create(vm, name)));
} }

View File

@ -84,7 +84,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// 1. If type is "language", then // 1. If type is "language", then
if (type == DisplayNames::Type::Language) { if (type == DisplayNames::Type::Language) {
// a. If code does not match the unicode_language_id production, throw a RangeError exception. // a. If code does not match the unicode_language_id production, throw a RangeError exception.
if (!::Locale::parse_unicode_language_id(code).has_value()) if (!Unicode::parse_unicode_language_id(code).has_value())
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "language"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "language"sv);
// b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception. // b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception.
@ -99,7 +99,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// 2. If type is "region", then // 2. If type is "region", then
if (type == DisplayNames::Type::Region) { if (type == DisplayNames::Type::Region) {
// a. If code does not match the unicode_region_subtag production, throw a RangeError exception. // a. If code does not match the unicode_region_subtag production, throw a RangeError exception.
if (!::Locale::is_unicode_region_subtag(code)) if (!Unicode::is_unicode_region_subtag(code))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "region"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "region"sv);
// b. Return the ASCII-uppercase of code. // b. Return the ASCII-uppercase of code.
@ -109,7 +109,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// 3. If type is "script", then // 3. If type is "script", then
if (type == DisplayNames::Type::Script) { if (type == DisplayNames::Type::Script) {
// a. If code does not match the unicode_script_subtag production, throw a RangeError exception. // a. If code does not match the unicode_script_subtag production, throw a RangeError exception.
if (!::Locale::is_unicode_script_subtag(code)) if (!Unicode::is_unicode_script_subtag(code))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "script"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "script"sv);
// Assert: The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive). // Assert: The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive).
@ -125,7 +125,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// 4. If type is "calendar", then // 4. If type is "calendar", then
if (type == DisplayNames::Type::Calendar) { if (type == DisplayNames::Type::Calendar) {
// a. If code does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If code does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(code)) if (!Unicode::is_type_identifier(code))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "calendar"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "calendar"sv);
// b. If code uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance, throw a RangeError exception. // b. If code uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance, throw a RangeError exception.

View File

@ -10,8 +10,8 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/DisplayNames.h> #include <LibUnicode/DisplayNames.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -41,9 +41,9 @@ public:
String const& locale() const { return m_locale; } String const& locale() const { return m_locale; }
void set_locale(String locale) { m_locale = move(locale); } void set_locale(String locale) { m_locale = move(locale); }
::Locale::Style style() const { return m_style; } Unicode::Style style() const { return m_style; }
void set_style(StringView style) { m_style = ::Locale::style_from_string(style); } void set_style(StringView style) { m_style = Unicode::style_from_string(style); }
StringView style_string() const { return ::Locale::style_to_string(m_style); } StringView style_string() const { return Unicode::style_to_string(m_style); }
Type type() const { return m_type; } Type type() const { return m_type; }
void set_type(StringView type); void set_type(StringView type);
@ -54,18 +54,18 @@ public:
StringView fallback_string() const; StringView fallback_string() const;
bool has_language_display() const { return m_language_display.has_value(); } bool has_language_display() const { return m_language_display.has_value(); }
::Locale::LanguageDisplay language_display() const { return *m_language_display; } Unicode::LanguageDisplay language_display() const { return *m_language_display; }
void set_language_display(StringView language_display) { m_language_display = ::Locale::language_display_from_string(language_display); } void set_language_display(StringView language_display) { m_language_display = Unicode::language_display_from_string(language_display); }
StringView language_display_string() const { return ::Locale::language_display_to_string(*m_language_display); } StringView language_display_string() const { return Unicode::language_display_to_string(*m_language_display); }
private: private:
DisplayNames(Object& prototype); DisplayNames(Object& prototype);
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]] Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
Type m_type { Type::Invalid }; // [[Type]] Type m_type { Type::Invalid }; // [[Type]]
Fallback m_fallback { Fallback::Invalid }; // [[Fallback]] Fallback m_fallback { Fallback::Invalid }; // [[Fallback]]
Optional<::Locale::LanguageDisplay> m_language_display; // [[LanguageDisplay]] Optional<Unicode::LanguageDisplay> m_language_display; // [[LanguageDisplay]]
}; };
ThrowCompletionOr<Value> canonical_code_for_display_names(VM&, DisplayNames::Type, StringView code); ThrowCompletionOr<Value> canonical_code_for_display_names(VM&, DisplayNames::Type, StringView code);

View File

@ -11,7 +11,7 @@
#include <LibJS/Runtime/Intl/DisplayNames.h> #include <LibJS/Runtime/Intl/DisplayNames.h>
#include <LibJS/Runtime/Intl/DisplayNamesConstructor.h> #include <LibJS/Runtime/Intl/DisplayNamesConstructor.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h> #include <LibJS/Runtime/Temporal/AbstractOperations.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -142,7 +142,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesConstructor::supported_locales_of)
auto options = vm.argument(1); auto options = vm.argument(1);
// 1. Let availableLocales be %DisplayNames%.[[AvailableLocales]]. // 1. Let availableLocales be %DisplayNames%.[[AvailableLocales]].
// No-op, availability of each requested locale is checked via ::Locale::is_locale_available() // No-op, availability of each requested locale is checked via Unicode::is_locale_available()
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales)); auto requested_locales = TRY(canonicalize_locale_list(vm, locales));

View File

@ -9,7 +9,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/DisplayNames.h> #include <LibJS/Runtime/Intl/DisplayNames.h>
#include <LibJS/Runtime/Intl/DisplayNamesPrototype.h> #include <LibJS/Runtime/Intl/DisplayNamesPrototype.h>
#include <LibLocale/DisplayNames.h> #include <LibUnicode/DisplayNames.h>
namespace JS::Intl { namespace JS::Intl {
@ -57,22 +57,22 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
switch (display_names->type()) { switch (display_names->type()) {
case DisplayNames::Type::Language: case DisplayNames::Type::Language:
result = ::Locale::language_display_name(display_names->locale(), code_string, display_names->language_display()); result = Unicode::language_display_name(display_names->locale(), code_string, display_names->language_display());
break; break;
case DisplayNames::Type::Region: case DisplayNames::Type::Region:
result = ::Locale::region_display_name(display_names->locale(), code_string); result = Unicode::region_display_name(display_names->locale(), code_string);
break; break;
case DisplayNames::Type::Script: case DisplayNames::Type::Script:
result = ::Locale::script_display_name(display_names->locale(), code_string); result = Unicode::script_display_name(display_names->locale(), code_string);
break; break;
case DisplayNames::Type::Currency: case DisplayNames::Type::Currency:
result = ::Locale::currency_display_name(display_names->locale(), code_string, display_names->style()); result = Unicode::currency_display_name(display_names->locale(), code_string, display_names->style());
break; break;
case DisplayNames::Type::Calendar: case DisplayNames::Type::Calendar:
result = ::Locale::calendar_display_name(display_names->locale(), code_string); result = Unicode::calendar_display_name(display_names->locale(), code_string);
break; break;
case DisplayNames::Type::DateTimeField: case DisplayNames::Type::DateTimeField:
result = ::Locale::date_time_field_display_name(display_names->locale(), code_string, display_names->style()); result = Unicode::date_time_field_display_name(display_names->locale(), code_string, display_names->style());
break; break;
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View File

@ -735,7 +735,7 @@ Vector<DurationFormatPart> list_format_parts(VM& vm, DurationFormat const& durat
} }
// 5. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle). // 5. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
auto locale_list_style = ::Locale::style_to_string(static_cast<::Locale::Style>(list_style)); auto locale_list_style = Unicode::style_to_string(static_cast<Unicode::Style>(list_style));
MUST(list_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, locale_list_style))); MUST(list_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, locale_list_style)));
// 6. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »). // 6. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
@ -925,7 +925,7 @@ Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFor
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format_unit))); MUST(number_format_options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format_unit)));
// 8. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style). // 8. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
auto locale_style = ::Locale::style_to_string(static_cast<::Locale::Style>(style)); auto locale_style = Unicode::style_to_string(static_cast<Unicode::Style>(style));
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, locale_style))); MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, locale_style)));
// 9. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »). // 9. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).

View File

@ -12,7 +12,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Temporal/Duration.h> #include <LibJS/Runtime/Temporal/Duration.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -36,9 +36,9 @@ public:
TwoDigit, TwoDigit,
Fractional, Fractional,
}; };
static_assert(to_underlying(ValueStyle::Long) == to_underlying(::Locale::Style::Long)); static_assert(to_underlying(ValueStyle::Long) == to_underlying(Unicode::Style::Long));
static_assert(to_underlying(ValueStyle::Short) == to_underlying(::Locale::Style::Short)); static_assert(to_underlying(ValueStyle::Short) == to_underlying(Unicode::Style::Short));
static_assert(to_underlying(ValueStyle::Narrow) == to_underlying(::Locale::Style::Narrow)); static_assert(to_underlying(ValueStyle::Narrow) == to_underlying(Unicode::Style::Narrow));
enum class Display { enum class Display {
Auto, Auto,

View File

@ -11,7 +11,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/DurationFormat.h> #include <LibJS/Runtime/Intl/DurationFormat.h>
#include <LibJS/Runtime/Intl/DurationFormatConstructor.h> #include <LibJS/Runtime/Intl/DurationFormatConstructor.h>
#include <LibLocale/DurationFormat.h> #include <LibUnicode/DurationFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -70,7 +70,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
// 7. If numberingSystem is not undefined, then // 7. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) { if (!numbering_system.is_undefined()) {
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(numbering_system.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
} }
@ -94,7 +94,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
// 13. Let dataLocale be durationFormat.[[DataLocale]]. // 13. Let dataLocale be durationFormat.[[DataLocale]].
// 14. Let dataLocaleData be durationFormat.[[LocaleData]].[[<dataLocale>]]. // 14. Let dataLocaleData be durationFormat.[[LocaleData]].[[<dataLocale>]].
// 15. Let digitalFormat be dataLocaleData.[[DigitalFormat]]. // 15. Let digitalFormat be dataLocaleData.[[DigitalFormat]].
auto digital_format = ::Locale::digital_format(duration_format->locale()); auto digital_format = Unicode::digital_format(duration_format->locale());
// 16. Let twoDigitHours be digitalFormat.[[TwoDigitHours]]. // 16. Let twoDigitHours be digitalFormat.[[TwoDigitHours]].
// 17. Set durationFormat.[[TwoDigitHours]] to twoDigitHours. // 17. Set durationFormat.[[TwoDigitHours]] to twoDigitHours.

View File

@ -21,11 +21,11 @@
#include <LibJS/Runtime/Intl/SegmenterConstructor.h> #include <LibJS/Runtime/Intl/SegmenterConstructor.h>
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h> #include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
#include <LibJS/Runtime/Temporal/TimeZone.h> #include <LibJS/Runtime/Temporal/TimeZone.h>
#include <LibLocale/DateTimeFormat.h>
#include <LibLocale/Locale.h>
#include <LibLocale/NumberFormat.h>
#include <LibLocale/UnicodeKeywords.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <LibUnicode/DateTimeFormat.h>
#include <LibUnicode/Locale.h>
#include <LibUnicode/NumberFormat.h>
#include <LibUnicode/UnicodeKeywords.h>
namespace JS::Intl { namespace JS::Intl {
@ -124,22 +124,22 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
// 2. If key is "calendar", then // 2. If key is "calendar", then
if (key == "calendar"sv) { if (key == "calendar"sv) {
// a. Let list be ! AvailableCanonicalCalendars( ). // a. Let list be ! AvailableCanonicalCalendars( ).
list = ::Locale::available_calendars().span(); list = Unicode::available_calendars().span();
} }
// 3. Else if key is "collation", then // 3. Else if key is "collation", then
else if (key == "collation"sv) { else if (key == "collation"sv) {
// a. Let list be ! AvailableCanonicalCollations( ). // a. Let list be ! AvailableCanonicalCollations( ).
list = ::Locale::available_collations().span(); list = Unicode::available_collations().span();
} }
// 4. Else if key is "currency", then // 4. Else if key is "currency", then
else if (key == "currency"sv) { else if (key == "currency"sv) {
// a. Let list be ! AvailableCanonicalCurrencies( ). // a. Let list be ! AvailableCanonicalCurrencies( ).
list = ::Locale::available_currencies().span(); list = Unicode::available_currencies().span();
} }
// 5. Else if key is "numberingSystem", then // 5. Else if key is "numberingSystem", then
else if (key == "numberingSystem"sv) { else if (key == "numberingSystem"sv) {
// a. Let list be ! AvailableCanonicalNumberingSystems( ). // a. Let list be ! AvailableCanonicalNumberingSystems( ).
list = ::Locale::available_number_systems().span(); list = Unicode::available_number_systems().span();
} }
// 6. Else if key is "timeZone", then // 6. Else if key is "timeZone", then
else if (key == "timeZone"sv) { else if (key == "timeZone"sv) {

View File

@ -9,7 +9,7 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/ListFormat.h> #include <LibJS/Runtime/Intl/ListFormat.h>
#include <LibJS/Runtime/Iterator.h> #include <LibJS/Runtime/Iterator.h>
#include <LibLocale/ListFormat.h> #include <LibUnicode/ListFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -22,7 +22,7 @@ ListFormat::ListFormat(Object& prototype)
} }
// 13.5.2 CreatePartsFromList ( listFormat, list ), https://tc39.es/ecma402/#sec-createpartsfromlist // 13.5.2 CreatePartsFromList ( listFormat, list ), https://tc39.es/ecma402/#sec-createpartsfromlist
Vector<::Locale::ListFormat::Partition> create_parts_from_list(ListFormat const& list_format, ReadonlySpan<String> list) Vector<Unicode::ListFormat::Partition> create_parts_from_list(ListFormat const& list_format, ReadonlySpan<String> list)
{ {
return list_format.formatter().format_to_parts(list); return list_format.formatter().format_to_parts(list);
} }

View File

@ -11,8 +11,8 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/ListFormat.h> #include <LibUnicode/ListFormat.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -33,29 +33,29 @@ public:
String const& locale() const { return m_locale; } String const& locale() const { return m_locale; }
void set_locale(String locale) { m_locale = move(locale); } void set_locale(String locale) { m_locale = move(locale); }
::Locale::ListFormatType type() const { return m_type; } Unicode::ListFormatType type() const { return m_type; }
void set_type(StringView type) { m_type = ::Locale::list_format_type_from_string(type); } void set_type(StringView type) { m_type = Unicode::list_format_type_from_string(type); }
StringView type_string() const { return ::Locale::list_format_type_to_string(m_type); } StringView type_string() const { return Unicode::list_format_type_to_string(m_type); }
::Locale::Style style() const { return m_style; } Unicode::Style style() const { return m_style; }
void set_style(StringView style) { m_style = ::Locale::style_from_string(style); } void set_style(StringView style) { m_style = Unicode::style_from_string(style); }
StringView style_string() const { return ::Locale::style_to_string(m_style); } StringView style_string() const { return Unicode::style_to_string(m_style); }
::Locale::ListFormat const& formatter() const { return *m_formatter; } Unicode::ListFormat const& formatter() const { return *m_formatter; }
void set_formatter(NonnullOwnPtr<::Locale::ListFormat> formatter) { m_formatter = move(formatter); } void set_formatter(NonnullOwnPtr<Unicode::ListFormat> formatter) { m_formatter = move(formatter); }
private: private:
explicit ListFormat(Object& prototype); explicit ListFormat(Object& prototype);
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
::Locale::ListFormatType m_type { ::Locale::ListFormatType::Conjunction }; // [[Type]] Unicode::ListFormatType m_type { Unicode::ListFormatType::Conjunction }; // [[Type]]
::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]] Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
// Non-standard. Stores the ICU list formatter for the Intl object's formatting options. // Non-standard. Stores the ICU list formatter for the Intl object's formatting options.
OwnPtr<::Locale::ListFormat> m_formatter; OwnPtr<Unicode::ListFormat> m_formatter;
}; };
Vector<::Locale::ListFormat::Partition> create_parts_from_list(ListFormat const&, ReadonlySpan<String> list); Vector<Unicode::ListFormat::Partition> create_parts_from_list(ListFormat const&, ReadonlySpan<String> list);
String format_list(ListFormat const&, ReadonlySpan<String> list); String format_list(ListFormat const&, ReadonlySpan<String> list);
NonnullGCPtr<Array> format_list_to_parts(VM&, ListFormat const&, ReadonlySpan<String> list); NonnullGCPtr<Array> format_list_to_parts(VM&, ListFormat const&, ReadonlySpan<String> list);
ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM&, Value iterable); ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM&, Value iterable);

View File

@ -91,7 +91,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ListFormatConstructor::construct(Functio
// 14. Let resolvedLocaleData be r.[[LocaleData]]. // 14. Let resolvedLocaleData be r.[[LocaleData]].
// 15. Let dataLocaleTypes be resolvedLocaleData.[[<type>]]. // 15. Let dataLocaleTypes be resolvedLocaleData.[[<type>]].
// 16. Set listFormat.[[Templates]] to dataLocaleTypes.[[<style>]]. // 16. Set listFormat.[[Templates]] to dataLocaleTypes.[[<style>]].
auto formatter = ::Locale::ListFormat::create( auto formatter = Unicode::ListFormat::create(
list_format->locale(), list_format->locale(),
list_format->type(), list_format->type(),
list_format->style()); list_format->style());

View File

@ -8,10 +8,10 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/Locale.h> #include <LibJS/Runtime/Intl/Locale.h>
#include <LibLocale/DateTimeFormat.h>
#include <LibLocale/Locale.h>
#include <LibLocale/UnicodeKeywords.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <LibUnicode/DateTimeFormat.h>
#include <LibUnicode/Locale.h>
#include <LibUnicode/UnicodeKeywords.h>
namespace JS::Intl { namespace JS::Intl {
@ -65,10 +65,10 @@ NonnullGCPtr<Array> calendars_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production. // 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 4. Let list be a List of 1 or more unique canonical calendar identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for date and time formatting in locale. // 4. Let list be a List of 1 or more unique canonical calendar identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::available_calendars(locale); auto list = Unicode::available_calendars(locale);
// 5. Return ! CreateArrayFromListOrRestricted( list, restricted ). // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
return create_array_from_list_or_restricted(vm, move(list), move(restricted)); return create_array_from_list_or_restricted(vm, move(list), move(restricted));
@ -84,10 +84,10 @@ NonnullGCPtr<Array> collations_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production. // 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 4. Let list be a List of 1 or more unique canonical collation identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, ordered as if an Array of the same values had been sorted, using %Array.prototype.sort% using undefined as comparefn, of those in common use for string comparison in locale. The values "standard" and "search" must be excluded from list. // 4. Let list be a List of 1 or more unique canonical collation identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, ordered as if an Array of the same values had been sorted, using %Array.prototype.sort% using undefined as comparefn, of those in common use for string comparison in locale. The values "standard" and "search" must be excluded from list.
auto list = ::Locale::available_collations(locale); auto list = Unicode::available_collations(locale);
// 5. Return ! CreateArrayFromListOrRestricted( list, restricted ). // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
return create_array_from_list_or_restricted(vm, move(list), move(restricted)); return create_array_from_list_or_restricted(vm, move(list), move(restricted));
@ -103,10 +103,10 @@ NonnullGCPtr<Array> hour_cycles_of_locale(VM& vm, Locale const& locale_object)
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production. // 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 4. Let list be a List of 1 or more unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format ("h11", "h12") or the 24-hour format ("h23", "h24"), sorted in descending preference of those in common use for date and time formatting in locale. // 4. Let list be a List of 1 or more unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format ("h11", "h12") or the 24-hour format ("h23", "h24"), sorted in descending preference of those in common use for date and time formatting in locale.
auto list = ::Locale::available_hour_cycles(locale); auto list = Unicode::available_hour_cycles(locale);
// 5. Return ! CreateArrayFromListOrRestricted( list, restricted ). // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
return create_array_from_list_or_restricted(vm, move(list), move(restricted)); return create_array_from_list_or_restricted(vm, move(list), move(restricted));
@ -122,10 +122,10 @@ NonnullGCPtr<Array> numbering_systems_of_locale(VM& vm, Locale const& locale_obj
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 3. Assert: locale matches the unicode_locale_id production. // 3. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 4. Let list be a List of 1 or more unique canonical numbering system identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for formatting numeric values in locale. // 4. Let list be a List of 1 or more unique canonical numbering system identifiers, which must be lower case String values conforming to the type sequence from UTS 35 Unicode Locale Identifier, section 3.2, sorted in descending preference of those in common use for formatting numeric values in locale.
auto list = ::Locale::available_number_systems(locale); auto list = Unicode::available_number_systems(locale);
// 5. Return ! CreateArrayFromListOrRestricted( list, restricted ). // 5. Return ! CreateArrayFromListOrRestricted( list, restricted ).
return create_array_from_list_or_restricted(vm, move(list), move(restricted)); return create_array_from_list_or_restricted(vm, move(list), move(restricted));
@ -158,10 +158,10 @@ StringView character_direction_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production. // 2. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 3. If the default general ordering of characters (characterOrder) within a line in locale is right-to-left, return "rtl". // 3. If the default general ordering of characters (characterOrder) within a line in locale is right-to-left, return "rtl".
if (::Locale::is_locale_character_ordering_right_to_left(locale)) if (Unicode::is_locale_character_ordering_right_to_left(locale))
return "rtl"sv; return "rtl"sv;
// 4. Return "ltr". // 4. Return "ltr".
@ -255,30 +255,30 @@ StringView weekday_to_string(StringView weekday)
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
static u8 weekday_to_integer(Optional<::Locale::Weekday> const& weekday, ::Locale::Weekday falllback) static u8 weekday_to_integer(Optional<Unicode::Weekday> const& weekday, Unicode::Weekday falllback)
{ {
// NOTE: This fallback will be used if the ICU data lookup failed. Its value should be that of the // NOTE: This fallback will be used if the ICU data lookup failed. Its value should be that of the
// default region ("001") in the CLDR. // default region ("001") in the CLDR.
switch (weekday.value_or(falllback)) { switch (weekday.value_or(falllback)) {
case ::Locale::Weekday::Monday: case Unicode::Weekday::Monday:
return 1; return 1;
case ::Locale::Weekday::Tuesday: case Unicode::Weekday::Tuesday:
return 2; return 2;
case ::Locale::Weekday::Wednesday: case Unicode::Weekday::Wednesday:
return 3; return 3;
case ::Locale::Weekday::Thursday: case Unicode::Weekday::Thursday:
return 4; return 4;
case ::Locale::Weekday::Friday: case Unicode::Weekday::Friday:
return 5; return 5;
case ::Locale::Weekday::Saturday: case Unicode::Weekday::Saturday:
return 6; return 6;
case ::Locale::Weekday::Sunday: case Unicode::Weekday::Sunday:
return 7; return 7;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
static Vector<u8> weekend_of_locale(ReadonlySpan<::Locale::Weekday> const& weekend_days) static Vector<u8> weekend_of_locale(ReadonlySpan<Unicode::Weekday> const& weekend_days)
{ {
Vector<u8> weekend; Vector<u8> weekend;
weekend.ensure_capacity(weekend_days.size()); weekend.ensure_capacity(weekend_days.size());
@ -297,14 +297,14 @@ WeekInfo week_info_of_locale(Locale const& locale_object)
auto const& locale = locale_object.locale(); auto const& locale = locale_object.locale();
// 2. Assert: locale matches the unicode_locale_id production. // 2. Assert: locale matches the unicode_locale_id production.
VERIFY(::Locale::parse_unicode_locale_id(locale).has_value()); VERIFY(Unicode::parse_unicode_locale_id(locale).has_value());
// 3. Let r be a record whose fields are defined by Table 3, with values based on locale. // 3. Let r be a record whose fields are defined by Table 3, with values based on locale.
auto locale_week_info = ::Locale::week_info_of_locale(locale); auto locale_week_info = Unicode::week_info_of_locale(locale);
WeekInfo week_info {}; WeekInfo week_info {};
week_info.minimal_days = locale_week_info.minimal_days_in_first_week; week_info.minimal_days = locale_week_info.minimal_days_in_first_week;
week_info.first_day = weekday_to_integer(locale_week_info.first_day_of_week, ::Locale::Weekday::Monday); week_info.first_day = weekday_to_integer(locale_week_info.first_day_of_week, Unicode::Weekday::Monday);
week_info.weekend = weekend_of_locale(locale_week_info.weekend_days); week_info.weekend = weekend_of_locale(locale_week_info.weekend_days);
// 4. Let fw be loc.[[FirstDayOfWeek]]. // 4. Let fw be loc.[[FirstDayOfWeek]].

View File

@ -14,7 +14,7 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
namespace JS::Intl { namespace JS::Intl {

View File

@ -12,7 +12,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/Locale.h> #include <LibJS/Runtime/Intl/Locale.h>
#include <LibJS/Runtime/Intl/LocaleConstructor.h> #include <LibJS/Runtime/Intl/LocaleConstructor.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -55,23 +55,23 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
// 4. Let language be ? GetOption(options, "language", string, empty, undefined). // 4. Let language be ? GetOption(options, "language", string, empty, undefined).
// 5. If language is not undefined, then // 5. If language is not undefined, then
// a. If language does not match the unicode_language_subtag production, throw a RangeError exception. // a. If language does not match the unicode_language_subtag production, throw a RangeError exception.
auto language = TRY(get_string_option(vm, options, vm.names.language, ::Locale::is_unicode_language_subtag)); auto language = TRY(get_string_option(vm, options, vm.names.language, Unicode::is_unicode_language_subtag));
// 6. Let script be ? GetOption(options, "script", string, empty, undefined). // 6. Let script be ? GetOption(options, "script", string, empty, undefined).
// 7. If script is not undefined, then // 7. If script is not undefined, then
// a. If script does not match the unicode_script_subtag production, throw a RangeError exception. // a. If script does not match the unicode_script_subtag production, throw a RangeError exception.
auto script = TRY(get_string_option(vm, options, vm.names.script, ::Locale::is_unicode_script_subtag)); auto script = TRY(get_string_option(vm, options, vm.names.script, Unicode::is_unicode_script_subtag));
// 8. Let region be ? GetOption(options, "region", string, empty, undefined). // 8. Let region be ? GetOption(options, "region", string, empty, undefined).
// 9. If region is not undefined, then // 9. If region is not undefined, then
// a. If region does not match the unicode_region_subtag production, throw a RangeError exception. // a. If region does not match the unicode_region_subtag production, throw a RangeError exception.
auto region = TRY(get_string_option(vm, options, vm.names.region, ::Locale::is_unicode_region_subtag)); auto region = TRY(get_string_option(vm, options, vm.names.region, Unicode::is_unicode_region_subtag));
// 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag). // 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(tag); auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(tag);
// 11. Assert: tag matches the unicode_locale_id production. // 11. Assert: tag matches the unicode_locale_id production.
auto locale_id = ::Locale::parse_unicode_locale_id(canonicalized_tag); auto locale_id = Unicode::parse_unicode_locale_id(canonicalized_tag);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
// 12. Let languageId be the substring of tag corresponding to the unicode_language_id production. // 12. Let languageId be the substring of tag corresponding to the unicode_language_id production.
@ -111,20 +111,20 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
// 14.1.3 ApplyUnicodeExtensionToTag ( tag, options, relevantExtensionKeys ), https://tc39.es/ecma402/#sec-apply-unicode-extension-to-tag // 14.1.3 ApplyUnicodeExtensionToTag ( tag, options, relevantExtensionKeys ), https://tc39.es/ecma402/#sec-apply-unicode-extension-to-tag
static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKeys options, ReadonlySpan<StringView> relevant_extension_keys) static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKeys options, ReadonlySpan<StringView> relevant_extension_keys)
{ {
auto locale_id = ::Locale::parse_unicode_locale_id(tag); auto locale_id = Unicode::parse_unicode_locale_id(tag);
VERIFY(locale_id.has_value()); VERIFY(locale_id.has_value());
Vector<String> attributes; Vector<String> attributes;
Vector<::Locale::Keyword> keywords; Vector<Unicode::Keyword> keywords;
// 1. If tag contains a substring that is a Unicode locale extension sequence, then // 1. If tag contains a substring that is a Unicode locale extension sequence, then
for (auto& extension : locale_id->extensions) { for (auto& extension : locale_id->extensions) {
if (!extension.has<::Locale::LocaleExtension>()) if (!extension.has<Unicode::LocaleExtension>())
continue; continue;
// a. Let extension be the String value consisting of the substring of the Unicode locale extension sequence within tag. // a. Let extension be the String value consisting of the substring of the Unicode locale extension sequence within tag.
// b. Let components be ! UnicodeExtensionComponents(extension). // b. Let components be ! UnicodeExtensionComponents(extension).
auto& components = extension.get<::Locale::LocaleExtension>(); auto& components = extension.get<Unicode::LocaleExtension>();
// c. Let attributes be components.[[Attributes]]. // c. Let attributes be components.[[Attributes]].
attributes = move(components.attributes); attributes = move(components.attributes);
// d. Let keywords be components.[[Keywords]]. // d. Let keywords be components.[[Keywords]].
@ -159,7 +159,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 4. For each element key of relevantExtensionKeys, do // 4. For each element key of relevantExtensionKeys, do
for (auto const& key : relevant_extension_keys) { for (auto const& key : relevant_extension_keys) {
::Locale::Keyword* entry = nullptr; Unicode::Keyword* entry = nullptr;
Optional<String> value; Optional<String> value;
// a. If keywords contains an element whose [[Key]] is key, then // a. If keywords contains an element whose [[Key]] is key, then
@ -181,7 +181,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// e. If overrideValue is not undefined, then // e. If overrideValue is not undefined, then
if (override_value.has_value()) { if (override_value.has_value()) {
// i. Set value to CanonicalizeUValue(key, overrideValue). // i. Set value to CanonicalizeUValue(key, overrideValue).
value = ::Locale::canonicalize_unicode_extension_values(key, *override_value); value = Unicode::canonicalize_unicode_extension_values(key, *override_value);
// ii. If entry is not empty, then // ii. If entry is not empty, then
if (entry != nullptr) { if (entry != nullptr) {
@ -200,7 +200,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
} }
// 5. Let locale be the String value that is tag with any Unicode locale extension sequences removed. // 5. Let locale be the String value that is tag with any Unicode locale extension sequences removed.
locale_id->remove_extension_type<::Locale::LocaleExtension>(); locale_id->remove_extension_type<Unicode::LocaleExtension>();
auto locale = locale_id->to_string(); auto locale = locale_id->to_string();
// 6. If attributes is not empty or keywords is not empty, then // 6. If attributes is not empty or keywords is not empty, then
@ -294,13 +294,13 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
// 14. If calendar is not undefined, then // 14. If calendar is not undefined, then
// a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
// 15. Set opt.[[ca]] to calendar. // 15. Set opt.[[ca]] to calendar.
opt.ca = TRY(get_string_option(vm, *options, vm.names.calendar, ::Locale::is_type_identifier)); opt.ca = TRY(get_string_option(vm, *options, vm.names.calendar, Unicode::is_type_identifier));
// 16. Let collation be ? GetOption(options, "collation", string, empty, undefined). // 16. Let collation be ? GetOption(options, "collation", string, empty, undefined).
// 17. If collation is not undefined, then // 17. If collation is not undefined, then
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
// 18. Set opt.[[co]] to collation. // 18. Set opt.[[co]] to collation.
opt.co = TRY(get_string_option(vm, *options, vm.names.collation, ::Locale::is_type_identifier)); opt.co = TRY(get_string_option(vm, *options, vm.names.collation, Unicode::is_type_identifier));
// 19. Let fw be ? GetOption(options, "firstDayOfWeek", "string", « "mon", "tue", "wed", "thu", "fri", "sat", "sun", "0", "1", "2", "3", "4", "5", "6", "7" », undefined). // 19. Let fw be ? GetOption(options, "firstDayOfWeek", "string", « "mon", "tue", "wed", "thu", "fri", "sat", "sun", "0", "1", "2", "3", "4", "5", "6", "7" », undefined).
auto first_day_of_week = TRY(get_string_option(vm, *options, vm.names.firstDayOfWeek, nullptr, AK::Array { "mon"sv, "tue"sv, "wed"sv, "thu"sv, "fri"sv, "sat"sv, "sun"sv, "0"sv, "1"sv, "2"sv, "3"sv, "4"sv, "5"sv, "6"sv, "7"sv })); auto first_day_of_week = TRY(get_string_option(vm, *options, vm.names.firstDayOfWeek, nullptr, AK::Array { "mon"sv, "tue"sv, "wed"sv, "thu"sv, "fri"sv, "sat"sv, "sun"sv, "0"sv, "1"sv, "2"sv, "3"sv, "4"sv, "5"sv, "6"sv, "7"sv }));
@ -337,7 +337,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
// 31. If numberingSystem is not undefined, then // 31. If numberingSystem is not undefined, then
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
// 32. Set opt.[[nu]] to numberingSystem. // 32. Set opt.[[nu]] to numberingSystem.
opt.nu = TRY(get_string_option(vm, *options, vm.names.numberingSystem, ::Locale::is_type_identifier)); opt.nu = TRY(get_string_option(vm, *options, vm.names.numberingSystem, Unicode::is_type_identifier));
// 33. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys). // 33. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
auto result = apply_unicode_extension_to_tag(tag, move(opt), relevant_extension_keys); auto result = apply_unicode_extension_to_tag(tag, move(opt), relevant_extension_keys);

View File

@ -9,7 +9,7 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/Locale.h> #include <LibJS/Runtime/Intl/Locale.h>
#include <LibJS/Runtime/Intl/LocalePrototype.h> #include <LibJS/Runtime/Intl/LocalePrototype.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set maximal to loc.[[Locale]]. // 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set maximal to loc.[[Locale]].
auto maximal = ::Locale::add_likely_subtags(locale_object->locale()).value_or(locale_object->locale()); auto maximal = Unicode::add_likely_subtags(locale_object->locale()).value_or(locale_object->locale());
// 4. Return ! Construct(%Locale%, maximal). // 4. Return ! Construct(%Locale%, maximal).
return Locale::create(realm, locale_object, move(maximal)); return Locale::create(realm, locale_object, move(maximal));
@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set minimal to loc.[[Locale]]. // 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. If an error is signaled, set minimal to loc.[[Locale]].
auto minimal = ::Locale::remove_likely_subtags(locale_object->locale()).value_or(locale_object->locale()); auto minimal = Unicode::remove_likely_subtags(locale_object->locale()).value_or(locale_object->locale());
// 4. Return ! Construct(%Locale%, minimal). // 4. Return ! Construct(%Locale%, minimal).
return Locale::create(realm, locale_object, move(minimal)); return Locale::create(realm, locale_object, move(minimal));
@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]]. // 3. Let locale be loc.[[Locale]].
auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale()); auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
VERIFY(locale.has_value()); VERIFY(locale.has_value());
// 4. Return the substring of locale corresponding to the unicode_language_id production. // 4. Return the substring of locale corresponding to the unicode_language_id production.
@ -166,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::language)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]]. // 3. Let locale be loc.[[Locale]].
auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale()); auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
// 4. Assert: locale matches the unicode_locale_id production. // 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value()); VERIFY(locale.has_value());
@ -183,7 +183,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]]. // 3. Let locale be loc.[[Locale]].
auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale()); auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
// 4. Assert: locale matches the unicode_locale_id production. // 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value()); VERIFY(locale.has_value());
@ -204,7 +204,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]]. // 3. Let locale be loc.[[Locale]].
auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale()); auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
// 4. Assert: locale matches the unicode_locale_id production. // 4. Assert: locale matches the unicode_locale_id production.
VERIFY(locale.has_value()); VERIFY(locale.has_value());
@ -244,7 +244,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::get_time_zones)
auto locale_object = TRY(typed_this_object(vm)); auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]]. // 3. Let locale be loc.[[Locale]].
auto locale = ::Locale::parse_unicode_locale_id(locale_object->locale()); auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
// 4. If the unicode_language_id production of locale does not contain the ["-" unicode_region_subtag] sequence, return undefined. // 4. If the unicode_language_id production of locale does not contain the ["-" unicode_region_subtag] sequence, return undefined.
if (!locale.has_value() || !locale->language_id.region.has_value()) if (!locale.has_value() || !locale->language_id.region.has_value())

View File

@ -63,16 +63,16 @@ bool MathematicalValue::is_nan() const
return m_value.get<Symbol>() == Symbol::NotANumber; return m_value.get<Symbol>() == Symbol::NotANumber;
} }
::Locale::NumberFormat::Value MathematicalValue::to_value() const Unicode::NumberFormat::Value MathematicalValue::to_value() const
{ {
return m_value.visit( return m_value.visit(
[](double value) -> ::Locale::NumberFormat::Value { [](double value) -> Unicode::NumberFormat::Value {
return value; return value;
}, },
[](String const& value) -> ::Locale::NumberFormat::Value { [](String const& value) -> Unicode::NumberFormat::Value {
return value; return value;
}, },
[](auto symbol) -> ::Locale::NumberFormat::Value { [](auto symbol) -> Unicode::NumberFormat::Value {
switch (symbol) { switch (symbol) {
case Symbol::PositiveInfinity: case Symbol::PositiveInfinity:
return js_infinity().as_double(); return js_infinity().as_double();

View File

@ -11,7 +11,7 @@
#include <LibCrypto/BigInt/SignedBigInteger.h> #include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -61,7 +61,7 @@ public:
bool is_negative_zero() const; bool is_negative_zero() const;
bool is_nan() const; bool is_nan() const;
::Locale::NumberFormat::Value to_value() const; Unicode::NumberFormat::Value to_value() const;
private: private:
using ValueType = Variant<double, String, Symbol>; using ValueType = Variant<double, String, Symbol>;

View File

@ -16,8 +16,8 @@
#include <LibJS/Runtime/Intl/NumberFormatFunction.h> #include <LibJS/Runtime/Intl/NumberFormatFunction.h>
#include <LibJS/Runtime/Intl/PluralRules.h> #include <LibJS/Runtime/Intl/PluralRules.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/DisplayNames.h>
#include <LibUnicode/CurrencyCode.h> #include <LibUnicode/CurrencyCode.h>
#include <LibUnicode/DisplayNames.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
@ -61,11 +61,11 @@ StringView NumberFormatBase::computed_rounding_priority_string() const
Value NumberFormat::use_grouping_to_value(VM& vm) const Value NumberFormat::use_grouping_to_value(VM& vm) const
{ {
switch (m_use_grouping) { switch (m_use_grouping) {
case ::Locale::Grouping::Always: case Unicode::Grouping::Always:
case ::Locale::Grouping::Auto: case Unicode::Grouping::Auto:
case ::Locale::Grouping::Min2: case Unicode::Grouping::Min2:
return PrimitiveString::create(vm, ::Locale::grouping_to_string(m_use_grouping)); return PrimitiveString::create(vm, Unicode::grouping_to_string(m_use_grouping));
case ::Locale::Grouping::False: case Unicode::Grouping::False:
return Value(false); return Value(false);
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
@ -76,15 +76,15 @@ void NumberFormat::set_use_grouping(StringOrBoolean const& use_grouping)
{ {
use_grouping.visit( use_grouping.visit(
[this](StringView grouping) { [this](StringView grouping) {
m_use_grouping = ::Locale::grouping_from_string(grouping); m_use_grouping = Unicode::grouping_from_string(grouping);
}, },
[this](bool grouping) { [this](bool grouping) {
VERIFY(!grouping); VERIFY(!grouping);
m_use_grouping = ::Locale::Grouping::False; m_use_grouping = Unicode::Grouping::False;
}); });
} }
::Locale::RoundingOptions NumberFormatBase::rounding_options() const Unicode::RoundingOptions NumberFormatBase::rounding_options() const
{ {
return { return {
.type = m_rounding_type, .type = m_rounding_type,
@ -99,7 +99,7 @@ void NumberFormat::set_use_grouping(StringOrBoolean const& use_grouping)
}; };
} }
::Locale::DisplayOptions NumberFormat::display_options() const Unicode::DisplayOptions NumberFormat::display_options() const
{ {
return { return {
.style = m_style, .style = m_style,
@ -132,7 +132,7 @@ String format_numeric_to_string(NumberFormatBase const& intl_object, Mathematica
} }
// 15.5.4 PartitionNumberPattern ( numberFormat, x ), https://tc39.es/ecma402/#sec-partitionnumberpattern // 15.5.4 PartitionNumberPattern ( numberFormat, x ), https://tc39.es/ecma402/#sec-partitionnumberpattern
Vector<::Locale::NumberFormat::Partition> partition_number_pattern(NumberFormat const& number_format, MathematicalValue const& number) Vector<Unicode::NumberFormat::Partition> partition_number_pattern(NumberFormat const& number_format, MathematicalValue const& number)
{ {
return number_format.formatter().format_to_parts(number.to_value()); return number_format.formatter().format_to_parts(number.to_value());
} }
@ -232,7 +232,7 @@ ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM& vm, Value va
} }
// 15.5.19 PartitionNumberRangePattern ( numberFormat, x, y ), https://tc39.es/ecma402/#sec-partitionnumberrangepattern // 15.5.19 PartitionNumberRangePattern ( numberFormat, x, y ), https://tc39.es/ecma402/#sec-partitionnumberrangepattern
ThrowCompletionOr<Vector<::Locale::NumberFormat::Partition>> partition_number_range_pattern(VM& vm, NumberFormat const& number_format, MathematicalValue const& start, MathematicalValue const& end) ThrowCompletionOr<Vector<Unicode::NumberFormat::Partition>> partition_number_range_pattern(VM& vm, NumberFormat const& number_format, MathematicalValue const& start, MathematicalValue const& end)
{ {
// 1. If x is NaN or y is NaN, throw a RangeError exception. // 1. If x is NaN or y is NaN, throw a RangeError exception.
if (start.is_nan()) if (start.is_nan())

View File

@ -12,8 +12,8 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/MathematicalValue.h> #include <LibJS/Runtime/Intl/MathematicalValue.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -53,29 +53,29 @@ public:
int max_significant_digits() const { return *m_max_significant_digits; } int max_significant_digits() const { return *m_max_significant_digits; }
void set_max_significant_digits(int max_significant_digits) { m_max_significant_digits = max_significant_digits; } void set_max_significant_digits(int max_significant_digits) { m_max_significant_digits = max_significant_digits; }
::Locale::RoundingType rounding_type() const { return m_rounding_type; } Unicode::RoundingType rounding_type() const { return m_rounding_type; }
StringView rounding_type_string() const { return ::Locale::rounding_type_to_string(m_rounding_type); } StringView rounding_type_string() const { return Unicode::rounding_type_to_string(m_rounding_type); }
void set_rounding_type(::Locale::RoundingType rounding_type) { m_rounding_type = rounding_type; } void set_rounding_type(Unicode::RoundingType rounding_type) { m_rounding_type = rounding_type; }
ComputedRoundingPriority computed_rounding_priority() const { return m_computed_rounding_priority; } ComputedRoundingPriority computed_rounding_priority() const { return m_computed_rounding_priority; }
StringView computed_rounding_priority_string() const; StringView computed_rounding_priority_string() const;
void set_computed_rounding_priority(ComputedRoundingPriority computed_rounding_priority) { m_computed_rounding_priority = computed_rounding_priority; } void set_computed_rounding_priority(ComputedRoundingPriority computed_rounding_priority) { m_computed_rounding_priority = computed_rounding_priority; }
::Locale::RoundingMode rounding_mode() const { return m_rounding_mode; } Unicode::RoundingMode rounding_mode() const { return m_rounding_mode; }
StringView rounding_mode_string() const { return ::Locale::rounding_mode_to_string(m_rounding_mode); } StringView rounding_mode_string() const { return Unicode::rounding_mode_to_string(m_rounding_mode); }
void set_rounding_mode(StringView rounding_mode) { m_rounding_mode = ::Locale::rounding_mode_from_string(rounding_mode); } void set_rounding_mode(StringView rounding_mode) { m_rounding_mode = Unicode::rounding_mode_from_string(rounding_mode); }
int rounding_increment() const { return m_rounding_increment; } int rounding_increment() const { return m_rounding_increment; }
void set_rounding_increment(int rounding_increment) { m_rounding_increment = rounding_increment; } void set_rounding_increment(int rounding_increment) { m_rounding_increment = rounding_increment; }
::Locale::TrailingZeroDisplay trailing_zero_display() const { return m_trailing_zero_display; } Unicode::TrailingZeroDisplay trailing_zero_display() const { return m_trailing_zero_display; }
StringView trailing_zero_display_string() const { return ::Locale::trailing_zero_display_to_string(m_trailing_zero_display); } StringView trailing_zero_display_string() const { return Unicode::trailing_zero_display_to_string(m_trailing_zero_display); }
void set_trailing_zero_display(StringView trailing_zero_display) { m_trailing_zero_display = ::Locale::trailing_zero_display_from_string(trailing_zero_display); } void set_trailing_zero_display(StringView trailing_zero_display) { m_trailing_zero_display = Unicode::trailing_zero_display_from_string(trailing_zero_display); }
::Locale::RoundingOptions rounding_options() const; Unicode::RoundingOptions rounding_options() const;
::Locale::NumberFormat const& formatter() const { return *m_formatter; } Unicode::NumberFormat const& formatter() const { return *m_formatter; }
void set_formatter(NonnullOwnPtr<::Locale::NumberFormat> formatter) { m_formatter = move(formatter); } void set_formatter(NonnullOwnPtr<Unicode::NumberFormat> formatter) { m_formatter = move(formatter); }
protected: protected:
explicit NumberFormatBase(Object& prototype); explicit NumberFormatBase(Object& prototype);
@ -87,14 +87,14 @@ private:
Optional<int> m_max_fraction_digits {}; // [[MaximumFractionDigits]] Optional<int> m_max_fraction_digits {}; // [[MaximumFractionDigits]]
Optional<int> m_min_significant_digits {}; // [[MinimumSignificantDigits]] Optional<int> m_min_significant_digits {}; // [[MinimumSignificantDigits]]
Optional<int> m_max_significant_digits {}; // [[MaximumSignificantDigits]] Optional<int> m_max_significant_digits {}; // [[MaximumSignificantDigits]]
::Locale::RoundingType m_rounding_type; // [[RoundingType]] Unicode::RoundingType m_rounding_type; // [[RoundingType]]
ComputedRoundingPriority m_computed_rounding_priority { ComputedRoundingPriority::Invalid }; // [[ComputedRoundingPriority]] ComputedRoundingPriority m_computed_rounding_priority { ComputedRoundingPriority::Invalid }; // [[ComputedRoundingPriority]]
::Locale::RoundingMode m_rounding_mode; // [[RoundingMode]] Unicode::RoundingMode m_rounding_mode; // [[RoundingMode]]
int m_rounding_increment { 1 }; // [[RoundingIncrement]] int m_rounding_increment { 1 }; // [[RoundingIncrement]]
::Locale::TrailingZeroDisplay m_trailing_zero_display; // [[TrailingZeroDisplay]] Unicode::TrailingZeroDisplay m_trailing_zero_display; // [[TrailingZeroDisplay]]
// Non-standard. Stores the ICU number formatter for the Intl object's formatting options. // Non-standard. Stores the ICU number formatter for the Intl object's formatting options.
OwnPtr<::Locale::NumberFormat> m_formatter; OwnPtr<Unicode::NumberFormat> m_formatter;
}; };
class NumberFormat final : public NumberFormatBase { class NumberFormat final : public NumberFormatBase {
@ -114,82 +114,82 @@ public:
String const& numbering_system() const { return m_numbering_system; } String const& numbering_system() const { return m_numbering_system; }
void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); } void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); }
::Locale::NumberFormatStyle style() const { return m_style; } Unicode::NumberFormatStyle style() const { return m_style; }
StringView style_string() const { return ::Locale::number_format_style_to_string(m_style); } StringView style_string() const { return Unicode::number_format_style_to_string(m_style); }
void set_style(StringView style) { m_style = ::Locale::number_format_style_from_string(style); } void set_style(StringView style) { m_style = Unicode::number_format_style_from_string(style); }
bool has_currency() const { return m_currency.has_value(); } bool has_currency() const { return m_currency.has_value(); }
String const& currency() const { return m_currency.value(); } String const& currency() const { return m_currency.value(); }
void set_currency(String currency) { m_currency = move(currency); } void set_currency(String currency) { m_currency = move(currency); }
bool has_currency_display() const { return m_currency_display.has_value(); } bool has_currency_display() const { return m_currency_display.has_value(); }
::Locale::CurrencyDisplay currency_display() const { return *m_currency_display; } Unicode::CurrencyDisplay currency_display() const { return *m_currency_display; }
StringView currency_display_string() const { return ::Locale::currency_display_to_string(*m_currency_display); } StringView currency_display_string() const { return Unicode::currency_display_to_string(*m_currency_display); }
void set_currency_display(StringView currency_display) { m_currency_display = ::Locale::currency_display_from_string(currency_display); } void set_currency_display(StringView currency_display) { m_currency_display = Unicode::currency_display_from_string(currency_display); }
bool has_currency_sign() const { return m_currency_sign.has_value(); } bool has_currency_sign() const { return m_currency_sign.has_value(); }
::Locale::CurrencySign currency_sign() const { return *m_currency_sign; } Unicode::CurrencySign currency_sign() const { return *m_currency_sign; }
StringView currency_sign_string() const { return ::Locale::currency_sign_to_string(*m_currency_sign); } StringView currency_sign_string() const { return Unicode::currency_sign_to_string(*m_currency_sign); }
void set_currency_sign(StringView currency_sign) { m_currency_sign = ::Locale::currency_sign_from_string(currency_sign); } void set_currency_sign(StringView currency_sign) { m_currency_sign = Unicode::currency_sign_from_string(currency_sign); }
bool has_unit() const { return m_unit.has_value(); } bool has_unit() const { return m_unit.has_value(); }
String const& unit() const { return m_unit.value(); } String const& unit() const { return m_unit.value(); }
void set_unit(String unit) { m_unit = move(unit); } void set_unit(String unit) { m_unit = move(unit); }
bool has_unit_display() const { return m_unit_display.has_value(); } bool has_unit_display() const { return m_unit_display.has_value(); }
::Locale::Style unit_display() const { return *m_unit_display; } Unicode::Style unit_display() const { return *m_unit_display; }
StringView unit_display_string() const { return ::Locale::style_to_string(*m_unit_display); } StringView unit_display_string() const { return Unicode::style_to_string(*m_unit_display); }
void set_unit_display(StringView unit_display) { m_unit_display = ::Locale::style_from_string(unit_display); } void set_unit_display(StringView unit_display) { m_unit_display = Unicode::style_from_string(unit_display); }
::Locale::Grouping use_grouping() const { return m_use_grouping; } Unicode::Grouping use_grouping() const { return m_use_grouping; }
Value use_grouping_to_value(VM&) const; Value use_grouping_to_value(VM&) const;
void set_use_grouping(StringOrBoolean const& use_grouping); void set_use_grouping(StringOrBoolean const& use_grouping);
::Locale::Notation notation() const { return m_notation; } Unicode::Notation notation() const { return m_notation; }
StringView notation_string() const { return ::Locale::notation_to_string(m_notation); } StringView notation_string() const { return Unicode::notation_to_string(m_notation); }
void set_notation(StringView notation) { m_notation = ::Locale::notation_from_string(notation); } void set_notation(StringView notation) { m_notation = Unicode::notation_from_string(notation); }
bool has_compact_display() const { return m_compact_display.has_value(); } bool has_compact_display() const { return m_compact_display.has_value(); }
::Locale::CompactDisplay compact_display() const { return *m_compact_display; } Unicode::CompactDisplay compact_display() const { return *m_compact_display; }
StringView compact_display_string() const { return ::Locale::compact_display_to_string(*m_compact_display); } StringView compact_display_string() const { return Unicode::compact_display_to_string(*m_compact_display); }
void set_compact_display(StringView compact_display) { m_compact_display = ::Locale::compact_display_from_string(compact_display); } void set_compact_display(StringView compact_display) { m_compact_display = Unicode::compact_display_from_string(compact_display); }
::Locale::SignDisplay sign_display() const { return m_sign_display; } Unicode::SignDisplay sign_display() const { return m_sign_display; }
StringView sign_display_string() const { return ::Locale::sign_display_to_string(m_sign_display); } StringView sign_display_string() const { return Unicode::sign_display_to_string(m_sign_display); }
void set_sign_display(StringView sign_display) { m_sign_display = ::Locale::sign_display_from_string(sign_display); } void set_sign_display(StringView sign_display) { m_sign_display = Unicode::sign_display_from_string(sign_display); }
NativeFunction* bound_format() const { return m_bound_format; } NativeFunction* bound_format() const { return m_bound_format; }
void set_bound_format(NativeFunction* bound_format) { m_bound_format = bound_format; } void set_bound_format(NativeFunction* bound_format) { m_bound_format = bound_format; }
::Locale::DisplayOptions display_options() const; Unicode::DisplayOptions display_options() const;
private: private:
explicit NumberFormat(Object& prototype); explicit NumberFormat(Object& prototype);
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
String m_numbering_system; // [[NumberingSystem]] String m_numbering_system; // [[NumberingSystem]]
::Locale::NumberFormatStyle m_style; // [[Style]] Unicode::NumberFormatStyle m_style; // [[Style]]
Optional<String> m_currency; // [[Currency]] Optional<String> m_currency; // [[Currency]]
Optional<::Locale::CurrencyDisplay> m_currency_display; // [[CurrencyDisplay]] Optional<Unicode::CurrencyDisplay> m_currency_display; // [[CurrencyDisplay]]
Optional<::Locale::CurrencySign> m_currency_sign; // [[CurrencySign]] Optional<Unicode::CurrencySign> m_currency_sign; // [[CurrencySign]]
Optional<String> m_unit; // [[Unit]] Optional<String> m_unit; // [[Unit]]
Optional<::Locale::Style> m_unit_display; // [[UnitDisplay]] Optional<Unicode::Style> m_unit_display; // [[UnitDisplay]]
::Locale::Grouping m_use_grouping { ::Locale::Grouping::False }; // [[UseGrouping]] Unicode::Grouping m_use_grouping { Unicode::Grouping::False }; // [[UseGrouping]]
::Locale::Notation m_notation; // [[Notation]] Unicode::Notation m_notation; // [[Notation]]
Optional<::Locale::CompactDisplay> m_compact_display; // [[CompactDisplay]] Optional<Unicode::CompactDisplay> m_compact_display; // [[CompactDisplay]]
::Locale::SignDisplay m_sign_display; // [[SignDisplay]] Unicode::SignDisplay m_sign_display; // [[SignDisplay]]
GCPtr<NativeFunction> m_bound_format; // [[BoundFormat]] GCPtr<NativeFunction> m_bound_format; // [[BoundFormat]]
}; };
int currency_digits(StringView currency); int currency_digits(StringView currency);
String format_numeric_to_string(NumberFormatBase const& intl_object, MathematicalValue const& number); String format_numeric_to_string(NumberFormatBase const& intl_object, MathematicalValue const& number);
Vector<::Locale::NumberFormat::Partition> partition_number_pattern(NumberFormat const&, MathematicalValue const& number); Vector<Unicode::NumberFormat::Partition> partition_number_pattern(NumberFormat const&, MathematicalValue const& number);
String format_numeric(NumberFormat const&, MathematicalValue const& number); String format_numeric(NumberFormat const&, MathematicalValue const& number);
NonnullGCPtr<Array> format_numeric_to_parts(VM&, NumberFormat const&, MathematicalValue const& number); NonnullGCPtr<Array> format_numeric_to_parts(VM&, NumberFormat const&, MathematicalValue const& number);
ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM&, Value value); ThrowCompletionOr<MathematicalValue> to_intl_mathematical_value(VM&, Value value);
ThrowCompletionOr<Vector<::Locale::NumberFormat::Partition>> partition_number_range_pattern(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); ThrowCompletionOr<Vector<Unicode::NumberFormat::Partition>> partition_number_range_pattern(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end);
ThrowCompletionOr<String> format_numeric_range(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); ThrowCompletionOr<String> format_numeric_range(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end);
ThrowCompletionOr<NonnullGCPtr<Array>> format_numeric_range_to_parts(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end); ThrowCompletionOr<NonnullGCPtr<Array>> format_numeric_range_to_parts(VM&, NumberFormat const&, MathematicalValue const& start, MathematicalValue const& end);

View File

@ -9,7 +9,7 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h> #include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -104,7 +104,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
// 7. If numberingSystem is not undefined, then // 7. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) { if (!numbering_system.is_undefined()) {
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(numbering_system.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
} }
@ -134,7 +134,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
int default_max_fraction_digits = 0; int default_max_fraction_digits = 0;
// 16. If style is "currency", then // 16. If style is "currency", then
if (style == ::Locale::NumberFormatStyle::Currency) { if (style == Unicode::NumberFormatStyle::Currency) {
// a. Let currency be numberFormat.[[Currency]]. // a. Let currency be numberFormat.[[Currency]].
auto const& currency = number_format.currency(); auto const& currency = number_format.currency();
@ -156,7 +156,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
// i. Let mxfdDefault be 0. // i. Let mxfdDefault be 0.
// c. Else, // c. Else,
// i. Let mxfdDefault be 3. // i. Let mxfdDefault be 3.
default_max_fraction_digits = style == ::Locale::NumberFormatStyle::Percent ? 0 : 3; default_max_fraction_digits = style == Unicode::NumberFormatStyle::Percent ? 0 : 3;
} }
// 18. Let notation be ? GetOption(options, "notation", string, « "standard", "scientific", "engineering", "compact" », "standard"). // 18. Let notation be ? GetOption(options, "notation", string, « "standard", "scientific", "engineering", "compact" », "standard").
@ -175,7 +175,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
auto default_use_grouping = "auto"sv; auto default_use_grouping = "auto"sv;
// 23. If notation is "compact", then // 23. If notation is "compact", then
if (number_format.notation() == ::Locale::Notation::Compact) { if (number_format.notation() == Unicode::Notation::Compact) {
// a. Set numberFormat.[[CompactDisplay]] to compactDisplay. // a. Set numberFormat.[[CompactDisplay]] to compactDisplay.
number_format.set_compact_display(compact_display.as_string().utf8_string_view()); number_format.set_compact_display(compact_display.as_string().utf8_string_view());
@ -209,7 +209,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
number_format.set_sign_display(sign_display.as_string().utf8_string_view()); number_format.set_sign_display(sign_display.as_string().utf8_string_view());
// Non-standard, create an ICU number formatter for this Intl object. // Non-standard, create an ICU number formatter for this Intl object.
auto formatter = ::Locale::NumberFormat::create( auto formatter = Unicode::NumberFormat::create(
number_format.locale(), number_format.locale(),
number_format.numbering_system(), number_format.numbering_system(),
number_format.display_options(), number_format.display_options(),
@ -221,7 +221,7 @@ ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM& vm, N
} }
// 15.1.3 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation ), https://tc39.es/ecma402/#sec-setnfdigitoptions // 15.1.3 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation ), https://tc39.es/ecma402/#sec-setnfdigitoptions
ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, ::Locale::Notation notation) ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, Unicode::Notation notation)
{ {
// 1. Let mnid be ? GetNumberOption(options, "minimumIntegerDigits,", 1, 21, 1). // 1. Let mnid be ? GetNumberOption(options, "minimumIntegerDigits,", 1, 21, 1).
auto min_integer_digits = TRY(get_number_option(vm, options, vm.names.minimumIntegerDigits, 1, 21, 1)); auto min_integer_digits = TRY(get_number_option(vm, options, vm.names.minimumIntegerDigits, 1, 21, 1));
@ -299,7 +299,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
need_significant_digits = has_significant_digits; need_significant_digits = has_significant_digits;
// b. If hasSd is true, or hasFd is false and notation is "compact", then // b. If hasSd is true, or hasFd is false and notation is "compact", then
if (has_significant_digits || (!has_fraction_digits && notation == ::Locale::Notation::Compact)) { if (has_significant_digits || (!has_fraction_digits && notation == Unicode::Notation::Compact)) {
// i. Set needFd to false. // i. Set needFd to false.
need_fraction_digits = false; need_fraction_digits = false;
} }
@ -378,7 +378,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
intl_object.set_max_significant_digits(2); intl_object.set_max_significant_digits(2);
// e. Set intlObj.[[RoundingType]] to morePrecision. // e. Set intlObj.[[RoundingType]] to morePrecision.
intl_object.set_rounding_type(::Locale::RoundingType::MorePrecision); intl_object.set_rounding_type(Unicode::RoundingType::MorePrecision);
// f. Set intlObj.[[ComputedRoundingPriority]] to "morePrecision". // f. Set intlObj.[[ComputedRoundingPriority]] to "morePrecision".
intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::MorePrecision); intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::MorePrecision);
@ -386,7 +386,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 27. Else if roundingPriority is "morePrecision", then // 27. Else if roundingPriority is "morePrecision", then
else if (rounding_priority == "morePrecision"sv) { else if (rounding_priority == "morePrecision"sv) {
// a. Set intlObj.[[RoundingType]] to morePrecision. // a. Set intlObj.[[RoundingType]] to morePrecision.
intl_object.set_rounding_type(::Locale::RoundingType::MorePrecision); intl_object.set_rounding_type(Unicode::RoundingType::MorePrecision);
// b. Set intlObj.[[ComputedRoundingPriority]] to "morePrecision". // b. Set intlObj.[[ComputedRoundingPriority]] to "morePrecision".
intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::MorePrecision); intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::MorePrecision);
@ -394,7 +394,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 28. Else if roundingPriority is "lessPrecision", then // 28. Else if roundingPriority is "lessPrecision", then
else if (rounding_priority == "lessPrecision"sv) { else if (rounding_priority == "lessPrecision"sv) {
// a. Set intlObj.[[RoundingType]] to lessPrecision. // a. Set intlObj.[[RoundingType]] to lessPrecision.
intl_object.set_rounding_type(::Locale::RoundingType::LessPrecision); intl_object.set_rounding_type(Unicode::RoundingType::LessPrecision);
// b. Set intlObj.[[ComputedRoundingPriority]] to "lessPrecision". // b. Set intlObj.[[ComputedRoundingPriority]] to "lessPrecision".
intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::LessPrecision); intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::LessPrecision);
@ -402,7 +402,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 29. Else if hasSd is true, then // 29. Else if hasSd is true, then
else if (has_significant_digits) { else if (has_significant_digits) {
// a. Set intlObj.[[RoundingType]] to significantDigits. // a. Set intlObj.[[RoundingType]] to significantDigits.
intl_object.set_rounding_type(::Locale::RoundingType::SignificantDigits); intl_object.set_rounding_type(Unicode::RoundingType::SignificantDigits);
// b. Set intlObj.[[ComputedRoundingPriority]] to "auto". // b. Set intlObj.[[ComputedRoundingPriority]] to "auto".
intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::Auto); intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::Auto);
@ -410,7 +410,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 30. Else, // 30. Else,
else { else {
// a. Set intlObj.[[RoundingType]] to fractionDigits. // a. Set intlObj.[[RoundingType]] to fractionDigits.
intl_object.set_rounding_type(::Locale::RoundingType::FractionDigits); intl_object.set_rounding_type(Unicode::RoundingType::FractionDigits);
// b. Set intlObj.[[ComputedRoundingPriority]] to "auto". // b. Set intlObj.[[ComputedRoundingPriority]] to "auto".
intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::Auto); intl_object.set_computed_rounding_priority(NumberFormatBase::ComputedRoundingPriority::Auto);
@ -419,7 +419,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase
// 31. If roundingIncrement is not 1, then // 31. If roundingIncrement is not 1, then
if (rounding_increment != 1) { if (rounding_increment != 1) {
// a. If intlObj.[[RoundingType]] is not fractionDigits, throw a TypeError exception. // a. If intlObj.[[RoundingType]] is not fractionDigits, throw a TypeError exception.
if (intl_object.rounding_type() != ::Locale::RoundingType::FractionDigits) if (intl_object.rounding_type() != Unicode::RoundingType::FractionDigits)
return vm.throw_completion<TypeError>(ErrorType::IntlInvalidRoundingIncrementForRoundingType, *rounding_increment, intl_object.rounding_type_string()); return vm.throw_completion<TypeError>(ErrorType::IntlInvalidRoundingIncrementForRoundingType, *rounding_increment, intl_object.rounding_type_string());
// b. If intlObj.[[MaximumFractionDigits]] is not equal to intlObj.[[MinimumFractionDigits]], throw a RangeError exception. // b. If intlObj.[[MaximumFractionDigits]] is not equal to intlObj.[[MinimumFractionDigits]], throw a RangeError exception.
@ -448,7 +448,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
// 6. If currency is undefined, then // 6. If currency is undefined, then
if (currency.is_undefined()) { if (currency.is_undefined()) {
// a. If style is "currency", throw a TypeError exception. // a. If style is "currency", throw a TypeError exception.
if (intl_object.style() == ::Locale::NumberFormatStyle::Currency) if (intl_object.style() == Unicode::NumberFormatStyle::Currency)
return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "currency"sv, "style"sv, style); return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "currency"sv, "style"sv, style);
} }
// 7. Else, // 7. Else,
@ -468,7 +468,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
// 11. If unit is undefined, then // 11. If unit is undefined, then
if (unit.is_undefined()) { if (unit.is_undefined()) {
// a. If style is "unit", throw a TypeError exception. // a. If style is "unit", throw a TypeError exception.
if (intl_object.style() == ::Locale::NumberFormatStyle::Unit) if (intl_object.style() == Unicode::NumberFormatStyle::Unit)
return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "unit"sv, "style"sv, style); return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "unit"sv, "style"sv, style);
} }
// 12. Else, // 12. Else,
@ -480,7 +480,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
auto unit_display = TRY(get_option(vm, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv)); auto unit_display = TRY(get_option(vm, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv));
// 14. If style is "currency", then // 14. If style is "currency", then
if (intl_object.style() == ::Locale::NumberFormatStyle::Currency) { if (intl_object.style() == Unicode::NumberFormatStyle::Currency) {
// a. Set intlObj.[[Currency]] to the ASCII-uppercase of currency. // a. Set intlObj.[[Currency]] to the ASCII-uppercase of currency.
intl_object.set_currency(MUST(currency.as_string().utf8_string().to_uppercase())); intl_object.set_currency(MUST(currency.as_string().utf8_string().to_uppercase()));
@ -492,7 +492,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int
} }
// 15. If style is "unit", then // 15. If style is "unit", then
if (intl_object.style() == ::Locale::NumberFormatStyle::Unit) { if (intl_object.style() == Unicode::NumberFormatStyle::Unit) {
// a. Set intlObj.[[Unit]] to unit. // a. Set intlObj.[[Unit]] to unit.
intl_object.set_unit(unit.as_string().utf8_string()); intl_object.set_unit(unit.as_string().utf8_string());

View File

@ -31,7 +31,7 @@ private:
}; };
ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM&, NumberFormat&, Value locales_value, Value options_value); ThrowCompletionOr<NonnullGCPtr<NumberFormat>> initialize_number_format(VM&, NumberFormat&, Value locales_value, Value options_value);
ThrowCompletionOr<void> set_number_format_digit_options(VM&, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, ::Locale::Notation notation); ThrowCompletionOr<void> set_number_format_digit_options(VM&, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, Unicode::Notation notation);
ThrowCompletionOr<void> set_number_format_unit_options(VM&, NumberFormat& intl_object, Object const& options); ThrowCompletionOr<void> set_number_format_unit_options(VM&, NumberFormat& intl_object, Object const& options);
} }

View File

@ -17,13 +17,13 @@ PluralRules::PluralRules(Object& prototype)
} }
// 16.5.4 ResolvePlural ( pluralRules, n ), https://tc39.es/ecma402/#sec-resolveplural // 16.5.4 ResolvePlural ( pluralRules, n ), https://tc39.es/ecma402/#sec-resolveplural
::Locale::PluralCategory resolve_plural(PluralRules const& plural_rules, Value number) Unicode::PluralCategory resolve_plural(PluralRules const& plural_rules, Value number)
{ {
// 1. If n is not a finite Number, then // 1. If n is not a finite Number, then
if (!number.is_finite_number()) { if (!number.is_finite_number()) {
// a. Let s be ! ToString(n). // a. Let s be ! ToString(n).
// b. Return the Record { [[PluralCategory]]: "other", [[FormattedString]]: s }. // b. Return the Record { [[PluralCategory]]: "other", [[FormattedString]]: s }.
return ::Locale::PluralCategory::Other; return Unicode::PluralCategory::Other;
} }
// 2. Let locale be pluralRules.[[Locale]]. // 2. Let locale be pluralRules.[[Locale]].
@ -37,7 +37,7 @@ PluralRules::PluralRules(Object& prototype)
} }
// 16.5.6 ResolvePluralRange ( pluralRules, x, y ), https://tc39.es/ecma402/#sec-resolveplural // 16.5.6 ResolvePluralRange ( pluralRules, x, y ), https://tc39.es/ecma402/#sec-resolveplural
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM& vm, PluralRules const& plural_rules, Value start, Value end) ThrowCompletionOr<Unicode::PluralCategory> resolve_plural_range(VM& vm, PluralRules const& plural_rules, Value start, Value end)
{ {
// 1. If x is NaN or y is NaN, throw a RangeError exception. // 1. If x is NaN or y is NaN, throw a RangeError exception.
if (start.is_nan()) if (start.is_nan())

View File

@ -10,7 +10,7 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Intl/NumberFormat.h> #include <LibJS/Runtime/Intl/NumberFormat.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/PluralRules.h> #include <LibUnicode/PluralRules.h>
namespace JS::Intl { namespace JS::Intl {
@ -21,17 +21,17 @@ class PluralRules final : public NumberFormatBase {
public: public:
virtual ~PluralRules() override = default; virtual ~PluralRules() override = default;
::Locale::PluralForm type() const { return m_type; } Unicode::PluralForm type() const { return m_type; }
StringView type_string() const { return ::Locale::plural_form_to_string(m_type); } StringView type_string() const { return Unicode::plural_form_to_string(m_type); }
void set_type(StringView type) { m_type = ::Locale::plural_form_from_string(type); } void set_type(StringView type) { m_type = Unicode::plural_form_from_string(type); }
private: private:
explicit PluralRules(Object& prototype); explicit PluralRules(Object& prototype);
::Locale::PluralForm m_type { ::Locale::PluralForm::Cardinal }; // [[Type]] Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]]
}; };
::Locale::PluralCategory resolve_plural(PluralRules const&, Value number); Unicode::PluralCategory resolve_plural(PluralRules const&, Value number);
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM&, PluralRules const&, Value start, Value end); ThrowCompletionOr<Unicode::PluralCategory> resolve_plural_range(VM&, PluralRules const&, Value start, Value end);
} }

View File

@ -84,10 +84,10 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PluralRulesConstructor::construct(Functi
plural_rules->set_type(type.as_string().utf8_string_view()); plural_rules->set_type(type.as_string().utf8_string_view());
// 13. Perform ? SetNumberFormatDigitOptions(pluralRules, options, 0, 3, "standard"). // 13. Perform ? SetNumberFormatDigitOptions(pluralRules, options, 0, 3, "standard").
TRY(set_number_format_digit_options(vm, plural_rules, *options, 0, 3, ::Locale::Notation::Standard)); TRY(set_number_format_digit_options(vm, plural_rules, *options, 0, 3, Unicode::Notation::Standard));
// Non-standard, create an ICU number formatter for this Intl object. // Non-standard, create an ICU number formatter for this Intl object.
auto formatter = ::Locale::NumberFormat::create( auto formatter = Unicode::NumberFormat::create(
plural_rules->locale(), plural_rules->locale(),
{}, {},
{}, {},

View File

@ -9,7 +9,7 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/PluralRulesPrototype.h> #include <LibJS/Runtime/Intl/PluralRulesPrototype.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/PluralRules.h> #include <LibUnicode/PluralRules.h>
namespace JS::Intl { namespace JS::Intl {
@ -48,7 +48,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select)
// 4. Return ! ResolvePlural(pr, n).[[PluralCategory]]. // 4. Return ! ResolvePlural(pr, n).[[PluralCategory]].
auto plurality = resolve_plural(plural_rules, number); auto plurality = resolve_plural(plural_rules, number);
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality)); return PrimitiveString::create(vm, Unicode::plural_category_to_string(plurality));
} }
// 16.3.4 Intl.PluralRules.prototype.selectRange ( start, end ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange // 16.3.4 Intl.PluralRules.prototype.selectRange ( start, end ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 6. Return ? ResolvePluralRange(pr, x, y). // 6. Return ? ResolvePluralRange(pr, x, y).
auto plurality = TRY(resolve_plural_range(vm, plural_rules, x, y)); auto plurality = TRY(resolve_plural_range(vm, plural_rules, x, y));
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality)); return PrimitiveString::create(vm, Unicode::plural_category_to_string(plurality));
} }
// 16.3.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions // 16.3.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
@ -93,8 +93,8 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// 4. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]]. // 4. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]].
auto available_categories = plural_rules->formatter().available_plural_categories(); auto available_categories = plural_rules->formatter().available_plural_categories();
auto plural_categories = Array::create_from<::Locale::PluralCategory>(realm, available_categories, [&](auto category) { auto plural_categories = Array::create_from<Unicode::PluralCategory>(realm, available_categories, [&](auto category) {
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(category)); return PrimitiveString::create(vm, Unicode::plural_category_to_string(category));
}); });
// 5. For each row of Table 16, except the header row, in table order, do // 5. For each row of Table 16, except the header row, in table order, do

View File

@ -25,42 +25,42 @@ RelativeTimeFormat::RelativeTimeFormat(Object& prototype)
} }
// 17.5.1 SingularRelativeTimeUnit ( unit ), https://tc39.es/ecma402/#sec-singularrelativetimeunit // 17.5.1 SingularRelativeTimeUnit ( unit ), https://tc39.es/ecma402/#sec-singularrelativetimeunit
ThrowCompletionOr<::Locale::TimeUnit> singular_relative_time_unit(VM& vm, StringView unit) ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(VM& vm, StringView unit)
{ {
// 1. If unit is "seconds", return "second". // 1. If unit is "seconds", return "second".
if (unit == "seconds"sv) if (unit == "seconds"sv)
return ::Locale::TimeUnit::Second; return Unicode::TimeUnit::Second;
// 2. If unit is "minutes", return "minute". // 2. If unit is "minutes", return "minute".
if (unit == "minutes"sv) if (unit == "minutes"sv)
return ::Locale::TimeUnit::Minute; return Unicode::TimeUnit::Minute;
// 3. If unit is "hours", return "hour". // 3. If unit is "hours", return "hour".
if (unit == "hours"sv) if (unit == "hours"sv)
return ::Locale::TimeUnit::Hour; return Unicode::TimeUnit::Hour;
// 4. If unit is "days", return "day". // 4. If unit is "days", return "day".
if (unit == "days"sv) if (unit == "days"sv)
return ::Locale::TimeUnit::Day; return Unicode::TimeUnit::Day;
// 5. If unit is "weeks", return "week". // 5. If unit is "weeks", return "week".
if (unit == "weeks"sv) if (unit == "weeks"sv)
return ::Locale::TimeUnit::Week; return Unicode::TimeUnit::Week;
// 6. If unit is "months", return "month". // 6. If unit is "months", return "month".
if (unit == "months"sv) if (unit == "months"sv)
return ::Locale::TimeUnit::Month; return Unicode::TimeUnit::Month;
// 7. If unit is "quarters", return "quarter". // 7. If unit is "quarters", return "quarter".
if (unit == "quarters"sv) if (unit == "quarters"sv)
return ::Locale::TimeUnit::Quarter; return Unicode::TimeUnit::Quarter;
// 8. If unit is "years", return "year". // 8. If unit is "years", return "year".
if (unit == "years"sv) if (unit == "years"sv)
return ::Locale::TimeUnit::Year; return Unicode::TimeUnit::Year;
// 9. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", or "year", throw a RangeError exception. // 9. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", or "year", throw a RangeError exception.
// 10. Return unit. // 10. Return unit.
if (auto time_unit = ::Locale::time_unit_from_string(unit); time_unit.has_value()) if (auto time_unit = Unicode::time_unit_from_string(unit); time_unit.has_value())
return *time_unit; return *time_unit;
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidUnit, unit); return vm.throw_completion<RangeError>(ErrorType::IntlInvalidUnit, unit);
} }
// 17.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-PartitionRelativeTimePattern // 17.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-PartitionRelativeTimePattern
ThrowCompletionOr<Vector<::Locale::RelativeTimeFormat::Partition>> partition_relative_time_pattern(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit) ThrowCompletionOr<Vector<Unicode::RelativeTimeFormat::Partition>> partition_relative_time_pattern(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit)
{ {
// 1. If value is NaN, +∞𝔽, or -∞𝔽, throw a RangeError exception. // 1. If value is NaN, +∞𝔽, or -∞𝔽, throw a RangeError exception.
if (!Value(value).is_finite_number()) if (!Value(value).is_finite_number())
@ -76,7 +76,7 @@ ThrowCompletionOr<Vector<::Locale::RelativeTimeFormat::Partition>> partition_rel
ThrowCompletionOr<String> format_relative_time(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit) ThrowCompletionOr<String> format_relative_time(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit)
{ {
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit). // 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
auto time_unit = TRY([&]() -> ThrowCompletionOr<::Locale::TimeUnit> { auto time_unit = TRY([&]() -> ThrowCompletionOr<Unicode::TimeUnit> {
// NOTE: We short-circuit PartitionRelativeTimePattern as we do not need individual partitions. But we must still // NOTE: We short-circuit PartitionRelativeTimePattern as we do not need individual partitions. But we must still
// perform the NaN/Infinity sanity checks and unit parsing from its first steps. // perform the NaN/Infinity sanity checks and unit parsing from its first steps.

View File

@ -12,9 +12,9 @@
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
#include <LibLocale/RelativeTimeFormat.h> #include <LibUnicode/RelativeTimeFormat.h>
namespace JS::Intl { namespace JS::Intl {
@ -38,31 +38,31 @@ public:
String const& numbering_system() const { return m_numbering_system; } String const& numbering_system() const { return m_numbering_system; }
void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); } void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); }
::Locale::Style style() const { return m_style; } Unicode::Style style() const { return m_style; }
void set_style(StringView style) { m_style = ::Locale::style_from_string(style); } void set_style(StringView style) { m_style = Unicode::style_from_string(style); }
StringView style_string() const { return ::Locale::style_to_string(m_style); } StringView style_string() const { return Unicode::style_to_string(m_style); }
::Locale::NumericDisplay numeric() const { return m_numeric; } Unicode::NumericDisplay numeric() const { return m_numeric; }
void set_numeric(StringView numeric) { m_numeric = ::Locale::numeric_display_from_string(numeric); } void set_numeric(StringView numeric) { m_numeric = Unicode::numeric_display_from_string(numeric); }
StringView numeric_string() const { return ::Locale::numeric_display_to_string(m_numeric); } StringView numeric_string() const { return Unicode::numeric_display_to_string(m_numeric); }
::Locale::RelativeTimeFormat const& formatter() const { return *m_formatter; } Unicode::RelativeTimeFormat const& formatter() const { return *m_formatter; }
void set_formatter(NonnullOwnPtr<::Locale::RelativeTimeFormat> formatter) { m_formatter = move(formatter); } void set_formatter(NonnullOwnPtr<Unicode::RelativeTimeFormat> formatter) { m_formatter = move(formatter); }
private: private:
explicit RelativeTimeFormat(Object& prototype); explicit RelativeTimeFormat(Object& prototype);
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
String m_numbering_system; // [[NumberingSystem]] String m_numbering_system; // [[NumberingSystem]]
::Locale::Style m_style { ::Locale::Style::Long }; // [[Style]] Unicode::Style m_style { Unicode::Style::Long }; // [[Style]]
::Locale::NumericDisplay m_numeric { ::Locale::NumericDisplay::Always }; // [[Numeric]] Unicode::NumericDisplay m_numeric { Unicode::NumericDisplay::Always }; // [[Numeric]]
// Non-standard. Stores the ICU relative-time formatter for the Intl object's formatting options. // Non-standard. Stores the ICU relative-time formatter for the Intl object's formatting options.
OwnPtr<::Locale::RelativeTimeFormat> m_formatter; OwnPtr<Unicode::RelativeTimeFormat> m_formatter;
}; };
ThrowCompletionOr<::Locale::TimeUnit> singular_relative_time_unit(VM&, StringView unit); ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(VM&, StringView unit);
ThrowCompletionOr<Vector<::Locale::RelativeTimeFormat::Partition>> partition_relative_time_pattern(VM&, RelativeTimeFormat&, double value, StringView unit); ThrowCompletionOr<Vector<Unicode::RelativeTimeFormat::Partition>> partition_relative_time_pattern(VM&, RelativeTimeFormat&, double value, StringView unit);
ThrowCompletionOr<String> format_relative_time(VM&, RelativeTimeFormat&, double value, StringView unit); ThrowCompletionOr<String> format_relative_time(VM&, RelativeTimeFormat&, double value, StringView unit);
ThrowCompletionOr<NonnullGCPtr<Array>> format_relative_time_to_parts(VM&, RelativeTimeFormat&, double value, StringView unit); ThrowCompletionOr<NonnullGCPtr<Array>> format_relative_time_to_parts(VM&, RelativeTimeFormat&, double value, StringView unit);

View File

@ -10,7 +10,7 @@
#include <LibJS/Runtime/Intl/AbstractOperations.h> #include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Intl/RelativeTimeFormat.h> #include <LibJS/Runtime/Intl/RelativeTimeFormat.h>
#include <LibJS/Runtime/Intl/RelativeTimeFormatConstructor.h> #include <LibJS/Runtime/Intl/RelativeTimeFormatConstructor.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace JS::Intl { namespace JS::Intl {
@ -75,7 +75,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> RelativeTimeFormatConstructor::construct
// 9. If numberingSystem is not undefined, then // 9. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) { if (!numbering_system.is_undefined()) {
// a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception. // a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view())) if (!Unicode::is_type_identifier(numbering_system.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv); return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
} }
@ -111,7 +111,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> RelativeTimeFormatConstructor::construct
// 20. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%Intl.NumberFormat%, « locale »). // 20. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%Intl.NumberFormat%, « locale »).
// 21. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%Intl.PluralRules%, « locale »). // 21. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%Intl.PluralRules%, « locale »).
auto formatter = ::Locale::RelativeTimeFormat::create( auto formatter = Unicode::RelativeTimeFormat::create(
relative_time_format->locale(), relative_time_format->locale(),
relative_time_format->style()); relative_time_format->style());
relative_time_format->set_formatter(move(formatter)); relative_time_format->set_formatter(move(formatter));

View File

@ -13,7 +13,7 @@ namespace JS::Intl {
JS_DEFINE_ALLOCATOR(SegmentIterator); JS_DEFINE_ALLOCATOR(SegmentIterator);
// 18.6.1 CreateSegmentIterator ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject // 18.6.1 CreateSegmentIterator ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, ::Locale::Segmenter const& segmenter, Utf16View const& string, Segments const& segments) NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Unicode::Segmenter const& segmenter, Utf16View const& string, Segments const& segments)
{ {
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ». // 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList). // 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
@ -25,7 +25,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, ::Locale::Se
} }
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects // 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
SegmentIterator::SegmentIterator(Realm& realm, ::Locale::Segmenter const& segmenter, Utf16View const& string, Segments const& segments) SegmentIterator::SegmentIterator(Realm& realm, Unicode::Segmenter const& segmenter, Utf16View const& string, Segments const& segments)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segment_iterator_prototype()) : Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segment_iterator_prototype())
, m_iterating_segmenter(segmenter.clone()) , m_iterating_segmenter(segmenter.clone())
, m_iterated_string(string) , m_iterated_string(string)

View File

@ -9,7 +9,7 @@
#include <AK/Utf16View.h> #include <AK/Utf16View.h>
#include <LibJS/Runtime/Intl/Segmenter.h> #include <LibJS/Runtime/Intl/Segmenter.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
namespace JS::Intl { namespace JS::Intl {
@ -18,23 +18,23 @@ class SegmentIterator final : public Object {
JS_DECLARE_ALLOCATOR(SegmentIterator); JS_DECLARE_ALLOCATOR(SegmentIterator);
public: public:
static NonnullGCPtr<SegmentIterator> create(Realm&, ::Locale::Segmenter const&, Utf16View const&, Segments const&); static NonnullGCPtr<SegmentIterator> create(Realm&, Unicode::Segmenter const&, Utf16View const&, Segments const&);
virtual ~SegmentIterator() override = default; virtual ~SegmentIterator() override = default;
::Locale::Segmenter& iterating_segmenter() { return *m_iterating_segmenter; } Unicode::Segmenter& iterating_segmenter() { return *m_iterating_segmenter; }
Utf16View const& iterated_string() const { return m_iterated_string; } Utf16View const& iterated_string() const { return m_iterated_string; }
size_t iterated_string_next_segment_code_unit_index() const { return m_iterating_segmenter->current_boundary(); } size_t iterated_string_next_segment_code_unit_index() const { return m_iterating_segmenter->current_boundary(); }
Segments const& segments() { return m_segments; } Segments const& segments() { return m_segments; }
private: private:
SegmentIterator(Realm&, ::Locale::Segmenter const&, Utf16View const&, Segments const&); SegmentIterator(Realm&, Unicode::Segmenter const&, Utf16View const&, Segments const&);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
NonnullOwnPtr<::Locale::Segmenter> m_iterating_segmenter; // [[IteratingSegmenter]] NonnullOwnPtr<Unicode::Segmenter> m_iterating_segmenter; // [[IteratingSegmenter]]
Utf16View m_iterated_string; // [[IteratedString]] Utf16View m_iterated_string; // [[IteratedString]]
NonnullGCPtr<Segments const> m_segments; NonnullGCPtr<Segments const> m_segments;
}; };

View File

@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentIteratorPrototype::next)
auto end_index = find_boundary(segmenter, string, start_index, Direction::After); auto end_index = find_boundary(segmenter, string, start_index, Direction::After);
// 9. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to endIndex. // 9. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to endIndex.
// NOTE: This is already handled by LibLocale. // NOTE: This is already handled by LibUnicode.
// 10. Let segmentData be CreateSegmentDataObject(segmenter, string, startIndex, endIndex). // 10. Let segmentData be CreateSegmentDataObject(segmenter, string, startIndex, endIndex).
auto segment_data = TRY(create_segment_data_object(vm, segmenter, string, start_index, end_index)); auto segment_data = TRY(create_segment_data_object(vm, segmenter, string, start_index, end_index));

View File

@ -20,7 +20,7 @@ Segmenter::Segmenter(Object& prototype)
} }
// 18.7.1 CreateSegmentDataObject ( segmenter, string, startIndex, endIndex ), https://tc39.es/ecma402/#sec-createsegmentdataobject // 18.7.1 CreateSegmentDataObject ( segmenter, string, startIndex, endIndex ), https://tc39.es/ecma402/#sec-createsegmentdataobject
ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM& vm, ::Locale::Segmenter const& segmenter, Utf16View const& string, size_t start_index, size_t end_index) ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM& vm, Unicode::Segmenter const& segmenter, Utf16View const& string, size_t start_index, size_t end_index)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
@ -55,7 +55,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM& vm, ::Loc
auto granularity = segmenter.segmenter_granularity(); auto granularity = segmenter.segmenter_granularity();
// 11. If granularity is "word", then // 11. If granularity is "word", then
if (granularity == ::Locale::SegmenterGranularity::Word) { if (granularity == Unicode::SegmenterGranularity::Word) {
// a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]]. // a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]].
auto is_word_like = segmenter.is_current_boundary_word_like(); auto is_word_like = segmenter.is_current_boundary_word_like();
@ -68,7 +68,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM& vm, ::Loc
} }
// 18.8.1 FindBoundary ( segmenter, string, startIndex, direction ), https://tc39.es/ecma402/#sec-findboundary // 18.8.1 FindBoundary ( segmenter, string, startIndex, direction ), https://tc39.es/ecma402/#sec-findboundary
size_t find_boundary(::Locale::Segmenter& segmenter, Utf16View const& string, size_t start_index, Direction direction) size_t find_boundary(Unicode::Segmenter& segmenter, Utf16View const& string, size_t start_index, Direction direction)
{ {
// 1. Let len be the length of string. // 1. Let len be the length of string.
auto length = string.length_in_code_units(); auto length = string.length_in_code_units();
@ -83,7 +83,7 @@ size_t find_boundary(::Locale::Segmenter& segmenter, Utf16View const& string, si
if (direction == Direction::Before) { if (direction == Direction::Before) {
// a. Search string for the last segmentation boundary that is preceded by at most startIndex code units from // a. Search string for the last segmentation boundary that is preceded by at most startIndex code units from
// the beginning, using locale locale and text element granularity granularity. // the beginning, using locale locale and text element granularity granularity.
auto boundary = segmenter.previous_boundary(start_index, ::Locale::Segmenter::Inclusive::Yes); auto boundary = segmenter.previous_boundary(start_index, Unicode::Segmenter::Inclusive::Yes);
// b. If a boundary is found, return the count of code units in string preceding it. // b. If a boundary is found, return the count of code units in string preceding it.
if (boundary.has_value()) if (boundary.has_value())

View File

@ -9,7 +9,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
namespace JS::Intl { namespace JS::Intl {
@ -23,29 +23,29 @@ public:
String const& locale() const { return m_locale; } String const& locale() const { return m_locale; }
void set_locale(String locale) { m_locale = move(locale); } void set_locale(String locale) { m_locale = move(locale); }
::Locale::SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; } Unicode::SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; }
void set_segmenter_granularity(StringView segmenter_granularity) { m_segmenter_granularity = ::Locale::segmenter_granularity_from_string(segmenter_granularity); } void set_segmenter_granularity(StringView segmenter_granularity) { m_segmenter_granularity = Unicode::segmenter_granularity_from_string(segmenter_granularity); }
StringView segmenter_granularity_string() const { return ::Locale::segmenter_granularity_to_string(m_segmenter_granularity); } StringView segmenter_granularity_string() const { return Unicode::segmenter_granularity_to_string(m_segmenter_granularity); }
::Locale::Segmenter const& segmenter() const { return *m_segmenter; } Unicode::Segmenter const& segmenter() const { return *m_segmenter; }
void set_segmenter(NonnullOwnPtr<::Locale::Segmenter> segmenter) { m_segmenter = move(segmenter); } void set_segmenter(NonnullOwnPtr<Unicode::Segmenter> segmenter) { m_segmenter = move(segmenter); }
private: private:
explicit Segmenter(Object& prototype); explicit Segmenter(Object& prototype);
String m_locale; // [[Locale]] String m_locale; // [[Locale]]
::Locale::SegmenterGranularity m_segmenter_granularity { ::Locale::SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]] Unicode::SegmenterGranularity m_segmenter_granularity { Unicode::SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
// Non-standard. Stores the ICU segmenter for the Intl object's segmentation options. // Non-standard. Stores the ICU segmenter for the Intl object's segmentation options.
OwnPtr<::Locale::Segmenter> m_segmenter; OwnPtr<Unicode::Segmenter> m_segmenter;
}; };
ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, ::Locale::Segmenter const&, Utf16View const&, size_t start_index, size_t end_index); ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, Unicode::Segmenter const&, Utf16View const&, size_t start_index, size_t end_index);
enum class Direction { enum class Direction {
Before, Before,
After, After,
}; };
size_t find_boundary(::Locale::Segmenter&, Utf16View const&, size_t start_index, Direction); size_t find_boundary(Unicode::Segmenter&, Utf16View const&, size_t start_index, Direction);
} }

View File

@ -83,7 +83,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> SegmenterConstructor::construct(Function
// 12. Set segmenter.[[SegmenterGranularity]] to granularity. // 12. Set segmenter.[[SegmenterGranularity]] to granularity.
segmenter->set_segmenter_granularity(granularity.as_string().utf8_string_view()); segmenter->set_segmenter_granularity(granularity.as_string().utf8_string_view());
auto locale_segmenter = ::Locale::Segmenter::create(segmenter->locale(), segmenter->segmenter_granularity()); auto locale_segmenter = Unicode::Segmenter::create(segmenter->locale(), segmenter->segmenter_granularity());
segmenter->set_segmenter(move(locale_segmenter)); segmenter->set_segmenter(move(locale_segmenter));
// 13. Return segmenter. // 13. Return segmenter.

View File

@ -13,7 +13,7 @@ namespace JS::Intl {
JS_DEFINE_ALLOCATOR(Segments); JS_DEFINE_ALLOCATOR(Segments);
// 18.5.1 CreateSegmentsObject ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject // 18.5.1 CreateSegmentsObject ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
NonnullGCPtr<Segments> Segments::create(Realm& realm, ::Locale::Segmenter const& segmenter, Utf16String string) NonnullGCPtr<Segments> Segments::create(Realm& realm, Unicode::Segmenter const& segmenter, Utf16String string)
{ {
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ». // 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList). // 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
@ -24,7 +24,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, ::Locale::Segmenter const&
} }
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects // 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
Segments::Segments(Realm& realm, ::Locale::Segmenter const& segmenter, Utf16String string) Segments::Segments(Realm& realm, Unicode::Segmenter const& segmenter, Utf16String string)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segments_prototype()) : Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().intl_segments_prototype())
, m_segments_segmenter(segmenter.clone()) , m_segments_segmenter(segmenter.clone())
, m_segments_string(move(string)) , m_segments_string(move(string))

View File

@ -9,7 +9,7 @@
#include <AK/Utf16View.h> #include <AK/Utf16View.h>
#include <LibJS/Runtime/Intl/Segmenter.h> #include <LibJS/Runtime/Intl/Segmenter.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
namespace JS::Intl { namespace JS::Intl {
@ -18,19 +18,19 @@ class Segments final : public Object {
JS_DECLARE_ALLOCATOR(Segments); JS_DECLARE_ALLOCATOR(Segments);
public: public:
static NonnullGCPtr<Segments> create(Realm&, ::Locale::Segmenter const&, Utf16String); static NonnullGCPtr<Segments> create(Realm&, Unicode::Segmenter const&, Utf16String);
virtual ~Segments() override = default; virtual ~Segments() override = default;
::Locale::Segmenter& segments_segmenter() const { return *m_segments_segmenter; } Unicode::Segmenter& segments_segmenter() const { return *m_segments_segmenter; }
Utf16View segments_string() const { return m_segments_string.view(); } Utf16View segments_string() const { return m_segments_string.view(); }
private: private:
Segments(Realm&, ::Locale::Segmenter const&, Utf16String); Segments(Realm&, Unicode::Segmenter const&, Utf16String);
NonnullOwnPtr<::Locale::Segmenter> m_segments_segmenter; // [[SegmentsSegmenter]] NonnullOwnPtr<Unicode::Segmenter> m_segments_segmenter; // [[SegmentsSegmenter]]
Utf16String m_segments_string; // [[SegmentsString]] Utf16String m_segments_string; // [[SegmentsString]]
}; };
} }

View File

@ -27,8 +27,8 @@
#include <LibJS/Runtime/Utf16String.h> #include <LibJS/Runtime/Utf16String.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/ValueInlines.h> #include <LibJS/Runtime/ValueInlines.h>
#include <LibLocale/Locale.h>
#include <LibUnicode/CharacterTypes.h> #include <LibUnicode/CharacterTypes.h>
#include <LibUnicode/Locale.h>
#include <LibUnicode/Normalize.h> #include <LibUnicode/Normalize.h>
#include <string.h> #include <string.h>
@ -1261,22 +1261,22 @@ static ThrowCompletionOr<String> transform_case(VM& vm, String const& string, Va
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(Intl::canonicalize_locale_list(vm, locales)); auto requested_locales = TRY(Intl::canonicalize_locale_list(vm, locales));
Optional<Locale::LocaleID> requested_locale; Optional<Unicode::LocaleID> requested_locale;
// 2. If requestedLocales is not an empty List, then // 2. If requestedLocales is not an empty List, then
if (!requested_locales.is_empty()) { if (!requested_locales.is_empty()) {
// a. Let requestedLocale be requestedLocales[0]. // a. Let requestedLocale be requestedLocales[0].
requested_locale = Locale::parse_unicode_locale_id(requested_locales[0]); requested_locale = Unicode::parse_unicode_locale_id(requested_locales[0]);
} }
// 3. Else, // 3. Else,
else { else {
// a. Let requestedLocale be ! DefaultLocale(). // a. Let requestedLocale be ! DefaultLocale().
requested_locale = Locale::parse_unicode_locale_id(Locale::default_locale()); requested_locale = Unicode::parse_unicode_locale_id(Unicode::default_locale());
} }
VERIFY(requested_locale.has_value()); VERIFY(requested_locale.has_value());
// 4. Let noExtensionsLocale be the String value that is requestedLocale with any Unicode locale extension sequences removed. // 4. Let noExtensionsLocale be the String value that is requestedLocale with any Unicode locale extension sequences removed.
requested_locale->remove_extension_type<Locale::LocaleExtension>(); requested_locale->remove_extension_type<Unicode::LocaleExtension>();
auto no_extensions_locale = requested_locale->to_string(); auto no_extensions_locale = requested_locale->to_string();
// 5. Let availableLocales be a List with language tags that includes the languages for which the Unicode Character Database contains language sensitive case mappings. Implementations may add additional language tags if they support case mapping for additional locales. // 5. Let availableLocales be a List with language tags that includes the languages for which the Unicode Character Database contains language sensitive case mappings. Implementations may add additional language tags if they support case mapping for additional locales.

View File

@ -7,4 +7,4 @@ set(SOURCES
) )
serenity_lib(LibLine line) serenity_lib(LibLine line)
target_link_libraries(LibLine PRIVATE LibCore LibLocale) target_link_libraries(LibLine PRIVATE LibCore LibUnicode)

View File

@ -21,7 +21,7 @@
#include <LibCore/Event.h> #include <LibCore/Event.h>
#include <LibCore/EventLoop.h> #include <LibCore/EventLoop.h>
#include <LibCore/Notifier.h> #include <LibCore/Notifier.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@ -1916,7 +1916,7 @@ StringMetrics Editor::actual_rendered_string_metrics(Utf32View const& view, RedB
auto mask_it = masks.begin(); auto mask_it = masks.begin();
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
Vector<size_t> grapheme_breaks; Vector<size_t> grapheme_breaks;
segmenter->for_each_boundary(view, [&](size_t offset) -> IterationDecision { segmenter->for_each_boundary(view, [&](size_t offset) -> IterationDecision {

View File

@ -1,19 +0,0 @@
set(SOURCES
DateTimeFormat.cpp
DurationFormat.cpp
DisplayNames.cpp
ICU.cpp
ListFormat.cpp
Locale.cpp
NumberFormat.cpp
PluralRules.cpp
RelativeTimeFormat.cpp
Segmenter.cpp
UnicodeKeywords.cpp
)
serenity_lib(LibLocale locale)
find_package(ICU REQUIRED COMPONENTS data i18n uc)
target_include_directories(LibLocale PRIVATE ${ICU_INCLUDE_DIRS})
target_link_libraries(LibLocale PUBLIC ${ICU_LIBRARIES})

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2021-2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
namespace Locale {
enum class CalendarPatternStyle;
enum class HourCycle;
enum class PluralCategory;
enum class Style;
enum class Weekday;
class NumberFormat;
class Segmenter;
struct CalendarPattern;
struct Keyword;
struct LanguageID;
struct ListFormatPart;
struct LocaleExtension;
struct LocaleID;
struct OtherExtension;
struct TransformedExtension;
struct TransformedField;
}

View File

@ -3,16 +3,28 @@ include(${SerenityOS_SOURCE_DIR}/Meta/CMake/unicode_data.cmake)
set(SOURCES set(SOURCES
CharacterTypes.cpp CharacterTypes.cpp
CurrencyCode.cpp CurrencyCode.cpp
DateTimeFormat.cpp
DisplayNames.cpp
DurationFormat.cpp
Emoji.cpp Emoji.cpp
ICU.cpp
IDNA.cpp IDNA.cpp
ListFormat.cpp
Locale.cpp
Normalize.cpp Normalize.cpp
NumberFormat.cpp
PluralRules.cpp
RelativeTimeFormat.cpp
Segmenter.cpp
String.cpp String.cpp
UnicodeKeywords.cpp
${UNICODE_DATA_SOURCES} ${UNICODE_DATA_SOURCES}
) )
set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED}) set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED})
serenity_lib(LibUnicode unicode) serenity_lib(LibUnicode unicode)
find_package(ICU REQUIRED COMPONENTS data uc) find_package(ICU REQUIRED COMPONENTS data i18n uc)
target_include_directories(LibUnicode PRIVATE ${ICU_INCLUDE_DIRS}) target_include_directories(LibUnicode PRIVATE ${ICU_INCLUDE_DIRS})
target_link_libraries(LibUnicode PUBLIC ${ICU_LIBRARIES}) target_link_libraries(LibUnicode PUBLIC ${ICU_LIBRARIES})

View File

@ -10,8 +10,8 @@
#include <AK/CharacterTypes.h> #include <AK/CharacterTypes.h>
#include <AK/Find.h> #include <AK/Find.h>
#include <AK/Traits.h> #include <AK/Traits.h>
#include <LibLocale/ICU.h>
#include <LibUnicode/CharacterTypes.h> #include <LibUnicode/CharacterTypes.h>
#include <LibUnicode/ICU.h>
#include <unicode/uchar.h> #include <unicode/uchar.h>
#include <unicode/uscript.h> #include <unicode/uscript.h>
@ -297,7 +297,7 @@ bool code_point_has_script(u32 code_point, Script script)
auto icu_code_point = static_cast<UChar32>(code_point); auto icu_code_point = static_cast<UChar32>(code_point);
auto icu_script = static_cast<UScriptCode>(script.value()); auto icu_script = static_cast<UScriptCode>(script.value());
if (auto result = uscript_getScript(icu_code_point, &status); Locale::icu_success(status)) if (auto result = uscript_getScript(icu_code_point, &status); icu_success(status))
return result == icu_script; return result == icu_script;
return false; return false;
} }

View File

@ -11,11 +11,11 @@
#include <AK/GenericLexer.h> #include <AK/GenericLexer.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/TypeCasts.h> #include <AK/TypeCasts.h>
#include <LibLocale/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
#include <LibLocale/PartitionRange.h> #include <LibUnicode/PartitionRange.h>
#include <stdlib.h> #include <stdlib.h>
#include <unicode/calendar.h> #include <unicode/calendar.h>
@ -27,7 +27,7 @@
#include <unicode/timezone.h> #include <unicode/timezone.h>
#include <unicode/ucal.h> #include <unicode/ucal.h>
namespace Locale { namespace Unicode {
DateTimeStyle date_time_style_from_string(StringView style) DateTimeStyle date_time_style_from_string(StringView style)
{ {

View File

@ -12,9 +12,9 @@
#include <AK/Time.h> #include <AK/Time.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
namespace Locale { namespace Unicode {
enum class DateTimeStyle { enum class DateTimeStyle {
Full, Full,

View File

@ -7,8 +7,8 @@
#define AK_DONT_REPLACE_STD #define AK_DONT_REPLACE_STD
#include <AK/Array.h> #include <AK/Array.h>
#include <LibLocale/DisplayNames.h> #include <LibUnicode/DisplayNames.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <unicode/dtptngen.h> #include <unicode/dtptngen.h>
#include <unicode/localebuilder.h> #include <unicode/localebuilder.h>
@ -16,7 +16,7 @@
#include <unicode/tznames.h> #include <unicode/tznames.h>
#include <unicode/udatpg.h> #include <unicode/udatpg.h>
namespace Locale { namespace Unicode {
LanguageDisplay language_display_from_string(StringView language_display) LanguageDisplay language_display_from_string(StringView language_display)
{ {

View File

@ -9,10 +9,10 @@
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <LibLocale/Locale.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <LibUnicode/Locale.h>
namespace Locale { namespace Unicode {
enum class LanguageDisplay { enum class LanguageDisplay {
Standard, Standard,

View File

@ -9,15 +9,15 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <AK/CharacterTypes.h> #include <AK/CharacterTypes.h>
#include <AK/GenericLexer.h> #include <AK/GenericLexer.h>
#include <LibLocale/DurationFormat.h> #include <LibUnicode/DurationFormat.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
#include <unicode/measfmt.h> #include <unicode/measfmt.h>
#include <unicode/measunit.h> #include <unicode/measunit.h>
#include <unicode/measure.h> #include <unicode/measure.h>
namespace Locale { namespace Unicode {
static constexpr bool is_not_ascii_digit(u32 code_point) static constexpr bool is_not_ascii_digit(u32 code_point)
{ {

View File

@ -8,7 +8,7 @@
#include <AK/String.h> #include <AK/String.h>
namespace Locale { namespace Unicode {
struct DigitalFormat { struct DigitalFormat {
String hours_minutes_separator { ":"_string }; String hours_minutes_separator { ":"_string };

View File

@ -11,10 +11,27 @@
namespace Unicode { namespace Unicode {
enum class BidiClass; class NumberFormat;
class Segmenter;
struct CalendarPattern;
struct CurrencyCode; struct CurrencyCode;
struct Emoji; struct Emoji;
struct Keyword;
struct LanguageID;
struct ListFormatPart;
struct LocaleExtension;
struct LocaleID;
struct OtherExtension;
struct TransformedExtension;
struct TransformedField;
enum class BidiClass;
enum class CalendarPatternStyle;
enum class HourCycle;
enum class PluralCategory;
enum class Style;
enum class Weekday;
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u32, GeneralCategory, CastToUnderlying, Comparison, Increment); AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u32, GeneralCategory, CastToUnderlying, Comparison, Increment);
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u32, Property, CastToUnderlying, Comparison, Increment); AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u32, Property, CastToUnderlying, Comparison, Increment);

View File

@ -9,14 +9,14 @@
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <AK/Utf16View.h> #include <AK/Utf16View.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <unicode/dtptngen.h> #include <unicode/dtptngen.h>
#include <unicode/locdspnm.h> #include <unicode/locdspnm.h>
#include <unicode/numsys.h> #include <unicode/numsys.h>
#include <unicode/tznames.h> #include <unicode/tznames.h>
namespace Locale { namespace Unicode {
static HashMap<String, OwnPtr<LocaleData>> s_locale_cache; static HashMap<String, OwnPtr<LocaleData>> s_locale_cache;

View File

@ -12,7 +12,7 @@
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <LibLocale/DurationFormat.h> #include <LibUnicode/DurationFormat.h>
#include <unicode/locid.h> #include <unicode/locid.h>
#include <unicode/stringpiece.h> #include <unicode/stringpiece.h>
@ -27,7 +27,7 @@ class NumberingSystem;
class TimeZoneNames; class TimeZoneNames;
U_NAMESPACE_END U_NAMESPACE_END
namespace Locale { namespace Unicode {
class LocaleData { class LocaleData {
public: public:

View File

@ -7,7 +7,7 @@
#define AK_DONT_REPLACE_STD #define AK_DONT_REPLACE_STD
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibUnicode/IDNA.h> #include <LibUnicode/IDNA.h>
#include <unicode/idna.h> #include <unicode/idna.h>
@ -31,14 +31,14 @@ ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& options)
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
auto idna = adopt_own_if_nonnull(icu::IDNA::createUTS46Instance(icu_options, status)); auto idna = adopt_own_if_nonnull(icu::IDNA::createUTS46Instance(icu_options, status));
if (Locale::icu_failure(status)) if (icu_failure(status))
return Error::from_string_literal("Unable to create an IDNA instance"); return Error::from_string_literal("Unable to create an IDNA instance");
StringBuilder builder { domain_name.as_string().length() }; StringBuilder builder { domain_name.as_string().length() };
icu::StringByteSink sink { &builder }; icu::StringByteSink sink { &builder };
icu::IDNAInfo info; icu::IDNAInfo info;
idna->nameToASCII_UTF8(Locale::icu_string_piece(domain_name.as_string()), sink, info, status); idna->nameToASCII_UTF8(icu_string_piece(domain_name.as_string()), sink, info, status);
auto errors = info.getErrors(); auto errors = info.getErrors();
@ -53,7 +53,7 @@ ErrorOr<String> to_ascii(Utf8View domain_name, ToAsciiOptions const& options)
errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG; errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
} }
if (Locale::icu_failure(status) || errors != 0) if (icu_failure(status) || errors != 0)
return Error::from_string_literal("Unable to convert domain to ASCII"); return Error::from_string_literal("Unable to convert domain to ASCII");
return builder.to_string(); return builder.to_string();

View File

@ -7,12 +7,12 @@
#define AK_DONT_REPLACE_STD #define AK_DONT_REPLACE_STD
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/ListFormat.h> #include <LibUnicode/ListFormat.h>
#include <unicode/listformatter.h> #include <unicode/listformatter.h>
namespace Locale { namespace Unicode {
ListFormatType list_format_type_from_string(StringView list_format_type) ListFormatType list_format_type_from_string(StringView list_format_type)
{ {

View File

@ -8,9 +8,9 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
namespace Locale { namespace Unicode {
enum class ListFormatType { enum class ListFormatType {
Conjunction, Conjunction,

View File

@ -11,13 +11,13 @@
#include <AK/HashTable.h> #include <AK/HashTable.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <unicode/localebuilder.h> #include <unicode/localebuilder.h>
#include <unicode/locid.h> #include <unicode/locid.h>
namespace Locale { namespace Unicode {
static bool is_key(StringView key) static bool is_key(StringView key)
{ {

View File

@ -12,9 +12,9 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Variant.h> #include <AK/Variant.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
namespace Locale { namespace Unicode {
struct LanguageID { struct LanguageID {
String to_string() const; String to_string() const;

View File

@ -8,7 +8,7 @@
#define AK_DONT_REPLACE_STD #define AK_DONT_REPLACE_STD
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibUnicode/Normalize.h> #include <LibUnicode/Normalize.h>
#include <unicode/normalizer2.h> #include <unicode/normalizer2.h>
@ -63,7 +63,7 @@ String normalize(StringView string, NormalizationForm form)
break; break;
} }
if (Locale::icu_failure(status)) if (icu_failure(status))
return MUST(String::from_utf8(string)); return MUST(String::from_utf8(string));
VERIFY(normalizer); VERIFY(normalizer);
@ -71,8 +71,8 @@ String normalize(StringView string, NormalizationForm form)
StringBuilder builder { string.length() }; StringBuilder builder { string.length() };
icu::StringByteSink sink { &builder }; icu::StringByteSink sink { &builder };
normalizer->normalizeUTF8(0, Locale::icu_string_piece(string), sink, nullptr, status); normalizer->normalizeUTF8(0, icu_string_piece(string), sink, nullptr, status);
if (Locale::icu_failure(status)) if (icu_failure(status))
return MUST(String::from_utf8(string)); return MUST(String::from_utf8(string));
return MUST(builder.to_string()); return MUST(builder.to_string());

View File

@ -9,17 +9,17 @@
#include <AK/CharacterTypes.h> #include <AK/CharacterTypes.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
#include <LibLocale/PartitionRange.h> #include <LibUnicode/PartitionRange.h>
#include <math.h> #include <math.h>
#include <unicode/numberformatter.h> #include <unicode/numberformatter.h>
#include <unicode/numberrangeformatter.h> #include <unicode/numberrangeformatter.h>
#include <unicode/plurrule.h> #include <unicode/plurrule.h>
namespace Locale { namespace Unicode {
NumberFormatStyle number_format_style_from_string(StringView number_format_style) NumberFormatStyle number_format_style_from_string(StringView number_format_style)
{ {

View File

@ -11,10 +11,10 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Variant.h> #include <AK/Variant.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
#include <LibLocale/PluralRules.h> #include <LibUnicode/PluralRules.h>
namespace Locale { namespace Unicode {
enum class NumberFormatStyle { enum class NumberFormatStyle {
Decimal, Decimal,

View File

@ -8,7 +8,7 @@
#include <AK/Types.h> #include <AK/Types.h>
namespace Locale { namespace Unicode {
struct PartitionRange { struct PartitionRange {
// ICU does not contain a field enumeration for "literal" partitions. Define a custom field so that we may provide // ICU does not contain a field enumeration for "literal" partitions. Define a custom field so that we may provide

View File

@ -4,9 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibLocale/PluralRules.h> #include <LibUnicode/PluralRules.h>
namespace Locale { namespace Unicode {
PluralForm plural_form_from_string(StringView plural_form) PluralForm plural_form_from_string(StringView plural_form)
{ {

View File

@ -8,7 +8,7 @@
#include <AK/StringView.h> #include <AK/StringView.h>
namespace Locale { namespace Unicode {
enum class PluralForm { enum class PluralForm {
Cardinal, Cardinal,

View File

@ -6,17 +6,17 @@
#define AK_DONT_REPLACE_STD #define AK_DONT_REPLACE_STD
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/NumberFormat.h> #include <LibUnicode/NumberFormat.h>
#include <LibLocale/PartitionRange.h> #include <LibUnicode/PartitionRange.h>
#include <LibLocale/RelativeTimeFormat.h> #include <LibUnicode/RelativeTimeFormat.h>
#include <unicode/decimfmt.h> #include <unicode/decimfmt.h>
#include <unicode/numfmt.h> #include <unicode/numfmt.h>
#include <unicode/reldatefmt.h> #include <unicode/reldatefmt.h>
namespace Locale { namespace Unicode {
Optional<TimeUnit> time_unit_from_string(StringView time_unit) Optional<TimeUnit> time_unit_from_string(StringView time_unit)
{ {

View File

@ -11,9 +11,9 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
namespace Locale { namespace Unicode {
// These are just the subset of fields in the CLDR required for ECMA-402. // These are just the subset of fields in the CLDR required for ECMA-402.
enum class TimeUnit { enum class TimeUnit {

View File

@ -8,15 +8,15 @@
#include <AK/Utf16View.h> #include <AK/Utf16View.h>
#include <AK/Utf32View.h> #include <AK/Utf32View.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/Locale.h> #include <LibUnicode/Locale.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <unicode/brkiter.h> #include <unicode/brkiter.h>
#include <unicode/utext.h> #include <unicode/utext.h>
#include <unicode/utf8.h> #include <unicode/utf8.h>
namespace Locale { namespace Unicode {
SegmenterGranularity segmenter_granularity_from_string(StringView segmenter_granularity) SegmenterGranularity segmenter_granularity_from_string(StringView segmenter_granularity)
{ {

View File

@ -11,7 +11,7 @@
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/StringView.h> #include <AK/StringView.h>
namespace Locale { namespace Unicode {
enum class SegmenterGranularity { enum class SegmenterGranularity {
Grapheme, Grapheme,

View File

@ -8,7 +8,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <unicode/bytestream.h> #include <unicode/bytestream.h>
#include <unicode/casemap.h> #include <unicode/casemap.h>
@ -44,8 +44,8 @@ ErrorOr<String> String::to_lowercase(Optional<StringView> const& locale) const
auto resolved_locale = resolve_locale(locale); auto resolved_locale = resolve_locale(locale);
icu::CaseMap::utf8ToLower(resolved_locale.locale, 0, Locale::icu_string_piece(*this), sink, nullptr, status); icu::CaseMap::utf8ToLower(resolved_locale.locale, 0, Unicode::icu_string_piece(*this), sink, nullptr, status);
if (Locale::icu_failure(status)) if (Unicode::icu_failure(status))
return Error::from_string_literal("Unable to convert string to lowercase"); return Error::from_string_literal("Unable to convert string to lowercase");
return builder.to_string_without_validation(); return builder.to_string_without_validation();
@ -60,8 +60,8 @@ ErrorOr<String> String::to_uppercase(Optional<StringView> const& locale) const
auto resolved_locale = resolve_locale(locale); auto resolved_locale = resolve_locale(locale);
icu::CaseMap::utf8ToUpper(resolved_locale.locale, 0, Locale::icu_string_piece(*this), sink, nullptr, status); icu::CaseMap::utf8ToUpper(resolved_locale.locale, 0, Unicode::icu_string_piece(*this), sink, nullptr, status);
if (Locale::icu_failure(status)) if (Unicode::icu_failure(status))
return Error::from_string_literal("Unable to convert string to uppercase"); return Error::from_string_literal("Unable to convert string to uppercase");
return builder.to_string_without_validation(); return builder.to_string_without_validation();
@ -80,8 +80,8 @@ ErrorOr<String> String::to_titlecase(Optional<StringView> const& locale, Trailin
if (trailing_code_point_transformation == TrailingCodePointTransformation::PreserveExisting) if (trailing_code_point_transformation == TrailingCodePointTransformation::PreserveExisting)
options |= U_TITLECASE_NO_LOWERCASE; options |= U_TITLECASE_NO_LOWERCASE;
icu::CaseMap::utf8ToTitle(resolved_locale.locale, options, nullptr, Locale::icu_string_piece(*this), sink, nullptr, status); icu::CaseMap::utf8ToTitle(resolved_locale.locale, options, nullptr, Unicode::icu_string_piece(*this), sink, nullptr, status);
if (Locale::icu_failure(status)) if (Unicode::icu_failure(status))
return Error::from_string_literal("Unable to convert string to titlecase"); return Error::from_string_literal("Unable to convert string to titlecase");
return builder.to_string_without_validation(); return builder.to_string_without_validation();
@ -93,8 +93,8 @@ static ErrorOr<void> build_casefold_string(StringView string, StringBuilder& bui
icu::StringByteSink sink { &builder }; icu::StringByteSink sink { &builder };
icu::CaseMap::utf8Fold(0, Locale::icu_string_piece(string), sink, nullptr, status); icu::CaseMap::utf8Fold(0, Unicode::icu_string_piece(string), sink, nullptr, status);
if (Locale::icu_failure(status)) if (Unicode::icu_failure(status))
return Error::from_string_literal("Unable to casefold string"); return Error::from_string_literal("Unable to casefold string");
return {}; return {};

View File

@ -8,9 +8,9 @@
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/ScopeGuard.h> #include <AK/ScopeGuard.h>
#include <LibLocale/DateTimeFormat.h> #include <LibUnicode/DateTimeFormat.h>
#include <LibLocale/ICU.h> #include <LibUnicode/ICU.h>
#include <LibLocale/UnicodeKeywords.h> #include <LibUnicode/UnicodeKeywords.h>
#include <unicode/calendar.h> #include <unicode/calendar.h>
#include <unicode/coll.h> #include <unicode/coll.h>
@ -18,7 +18,7 @@
#include <unicode/numsys.h> #include <unicode/numsys.h>
#include <unicode/ucurr.h> #include <unicode/ucurr.h>
namespace Locale { namespace Unicode {
template<typename Filter> template<typename Filter>
static Vector<String> icu_string_enumeration_to_list(OwnPtr<icu::StringEnumeration> enumeration, Filter&& filter) static Vector<String> icu_string_enumeration_to_list(OwnPtr<icu::StringEnumeration> enumeration, Filter&& filter)

View File

@ -10,7 +10,7 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Vector.h> #include <AK/Vector.h>
namespace Locale { namespace Unicode {
Vector<String> available_keyword_values(StringView locale, StringView key); Vector<String> available_keyword_values(StringView locale, StringView key);

View File

@ -756,7 +756,7 @@ find_package(unofficial-skia CONFIG REQUIRED)
serenity_lib(LibWeb web) serenity_lib(LibWeb web)
target_link_libraries(LibWeb PRIVATE LibCore LibCrypto LibJS LibHTTP LibGfx LibIPC LibLocale LibRegex LibSyntax LibTextCodec LibUnicode LibAudio LibMedia LibWasm LibXML LibIDL LibURL LibTLS unofficial::skia::skia) target_link_libraries(LibWeb PRIVATE LibCore LibCrypto LibJS LibHTTP LibGfx LibIPC LibRegex LibSyntax LibTextCodec LibUnicode LibAudio LibMedia LibWasm LibXML LibIDL LibURL LibTLS unofficial::skia::skia)
if (HAS_ACCELERATED_GRAPHICS) if (HAS_ACCELERATED_GRAPHICS)
target_link_libraries(LibWeb PRIVATE ${ACCEL_GFX_LIBS}) target_link_libraries(LibWeb PRIVATE ${ACCEL_GFX_LIBS})

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <LibWeb/Bindings/CharacterDataPrototype.h> #include <LibWeb/Bindings/CharacterDataPrototype.h>
#include <LibWeb/DOM/CharacterData.h> #include <LibWeb/DOM/CharacterData.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
@ -155,10 +155,10 @@ WebIDL::ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count
return replace_data(offset, count, String {}); return replace_data(offset, count, String {});
} }
Locale::Segmenter& CharacterData::segmenter() Unicode::Segmenter& CharacterData::segmenter()
{ {
if (!m_segmenter) { if (!m_segmenter) {
m_segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme); m_segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
m_segmenter->set_segmented_text(m_data); m_segmenter->set_segmented_text(m_data);
} }

View File

@ -7,7 +7,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/String.h>
#include <LibLocale/Forward.h> #include <LibUnicode/Forward.h>
#include <LibWeb/DOM/ChildNode.h> #include <LibWeb/DOM/ChildNode.h>
#include <LibWeb/DOM/Node.h> #include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/NonDocumentTypeChildNode.h> #include <LibWeb/DOM/NonDocumentTypeChildNode.h>
@ -41,7 +41,7 @@ public:
WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units); WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units);
WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&); WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&);
Locale::Segmenter& segmenter(); Unicode::Segmenter& segmenter();
protected: protected:
CharacterData(Document&, NodeType, String const&); CharacterData(Document&, NodeType, String const&);
@ -51,7 +51,7 @@ protected:
private: private:
String m_data; String m_data;
OwnPtr<Locale::Segmenter> m_segmenter; OwnPtr<Unicode::Segmenter> m_segmenter;
}; };
} }

View File

@ -6,7 +6,7 @@
*/ */
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <LibWeb/DOM/Node.h> #include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/Position.h> #include <LibWeb/DOM/Position.h>
#include <LibWeb/DOM/Text.h> #include <LibWeb/DOM/Text.h>

View File

@ -10,7 +10,7 @@
#include <LibGfx/Painter.h> #include <LibGfx/Painter.h>
#include <LibGfx/Quad.h> #include <LibGfx/Quad.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h> #include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/CanvasRenderingContext2D.h> #include <LibWeb/HTML/CanvasRenderingContext2D.h>
@ -520,7 +520,7 @@ CanvasRenderingContext2D::PreparedText CanvasRenderingContext2D::prepare_text(By
PreparedText prepared_text { {}, physical_alignment, { 0, 0, static_cast<int>(width), static_cast<int>(height) } }; PreparedText prepared_text { {}, physical_alignment, { 0, 0, static_cast<int>(width), static_cast<int>(height) } };
prepared_text.glyphs.ensure_capacity(replaced_text.bytes_as_string_view().length()); prepared_text.glyphs.ensure_capacity(replaced_text.bytes_as_string_view().length());
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme); auto segmenter = Unicode::Segmenter::create(Unicode::SegmenterGranularity::Grapheme);
size_t previous_boundary = 0; size_t previous_boundary = 0;
segmenter->for_each_boundary(replaced_text, [&](auto boundary) { segmenter->for_each_boundary(replaced_text, [&](auto boundary) {

View File

@ -6,7 +6,7 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibLocale/Segmenter.h> #include <LibUnicode/Segmenter.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Position.h> #include <LibWeb/DOM/Position.h>
#include <LibWeb/DOM/Range.h> #include <LibWeb/DOM/Range.h>

View File

@ -25,7 +25,7 @@ set(GENERATED_SOURCES
) )
serenity_bin(WebContent) serenity_bin(WebContent)
target_link_libraries(WebContent PRIVATE LibCore LibFileSystem LibIPC LibGfx LibAudio LibImageDecoderClient LibJS LibWebView LibWeb LibLocale LibMain LibURL) target_link_libraries(WebContent PRIVATE LibCore LibFileSystem LibIPC LibGfx LibAudio LibImageDecoderClient LibJS LibWebView LibWeb LibUnicode LibMain LibURL)
if (HAS_ACCELERATED_GRAPHICS) if (HAS_ACCELERATED_GRAPHICS)
target_compile_definitions(WebContent PRIVATE HAS_ACCELERATED_GRAPHICS) target_compile_definitions(WebContent PRIVATE HAS_ACCELERATED_GRAPHICS)

Some files were not shown because too many files have changed in this diff Show More