From d13142f015d1280c3486ee83e9492536c8e80910 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 30 Aug 2021 14:31:48 -0400 Subject: [PATCH] LibJS+LibUnicode: Store parsed Unicode locale data as full strings Originally, it was convenient to store the parsed Unicode locale data as views into the original string being parsed. But to implement locale aliases will require mutating the data that was parsed. To prepare for that, store the parsed data as proper strings. --- Tests/LibUnicode/TestUnicodeLocale.cpp | 4 ++-- .../LibJS/Runtime/Intl/AbstractOperations.cpp | 2 +- Userland/Libraries/LibUnicode/Locale.cpp | 16 +++++++------- Userland/Libraries/LibUnicode/Locale.h | 22 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Tests/LibUnicode/TestUnicodeLocale.cpp b/Tests/LibUnicode/TestUnicodeLocale.cpp index 5a14288f1a2..52dca559152 100644 --- a/Tests/LibUnicode/TestUnicodeLocale.cpp +++ b/Tests/LibUnicode/TestUnicodeLocale.cpp @@ -75,7 +75,7 @@ TEST_CASE(parse_unicode_locale_id) auto locale_id = Unicode::parse_unicode_locale_id(locale); EXPECT(!locale_id.has_value()); }; - auto pass = [](StringView locale, Optional expected_language, Optional expected_script, Optional expected_region, Vector expected_variants) { + auto pass = [](StringView locale, Optional expected_language, Optional expected_script, Optional expected_region, Vector expected_variants) { auto locale_id = Unicode::parse_unicode_locale_id(locale); VERIFY(locale_id.has_value()); @@ -252,7 +252,7 @@ TEST_CASE(parse_unicode_locale_id_with_private_use_extension) auto locale_id = Unicode::parse_unicode_locale_id(locale); EXPECT(!locale_id.has_value()); }; - auto pass = [](StringView locale, Vector const& expected_extension) { + auto pass = [](StringView locale, Vector const& expected_extension) { auto locale_id = Unicode::parse_unicode_locale_id(locale); VERIFY(locale_id.has_value()); EXPECT_EQ(locale_id->private_use_extensions, expected_extension); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index 767a92847c1..29609ac4153 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -19,7 +19,7 @@ namespace JS::Intl { // 6.2.2 IsStructurallyValidLanguageTag ( locale ), https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag static Optional is_structurally_valid_language_tag(StringView locale) { - auto contains_duplicate_variant = [](Vector& variants) { + auto contains_duplicate_variant = [](auto& variants) { if (variants.is_empty()) return false; diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index 62691697474..e9f8c3a6e9e 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -400,7 +400,7 @@ static Optional parse_extension(GenericLexer& lexer) return {}; } -static Vector parse_private_use_extensions(GenericLexer& lexer) +static Vector parse_private_use_extensions(GenericLexer& lexer) { // https://unicode.org/reports/tr35/#pu_extensions // @@ -411,8 +411,8 @@ static Vector parse_private_use_extensions(GenericLexer& lexer) if (!header.has_value()) return {}; - auto parse_values = [&]() -> Vector { - Vector extensions; + auto parse_values = [&]() -> Vector { + Vector extensions; while (true) { auto segment = consume_next_segment(lexer); @@ -491,18 +491,18 @@ Optional canonicalize_unicode_locale_id(LocaleID& locale_id) Title, }; - auto append_sep_and_string = [&](Optional const& string, Case case_ = Case::Lower) { + auto append_sep_and_string = [&](Optional const& string, Case case_ = Case::Lower) { if (!string.has_value()) return; switch (case_) { case Case::Upper: - builder.appendff("-{}", string->to_uppercase_string()); + builder.appendff("-{}", string->to_uppercase()); break; case Case::Lower: - builder.appendff("-{}", string->to_lowercase_string()); + builder.appendff("-{}", string->to_lowercase()); break; case Case::Title: - builder.appendff("-{}", string->to_titlecase_string()); + builder.appendff("-{}", string->to_titlecase()); break; } }; @@ -510,7 +510,7 @@ Optional canonicalize_unicode_locale_id(LocaleID& locale_id) if (!locale_id.language_id.language.has_value()) return {}; - builder.append(locale_id.language_id.language->to_lowercase_string()); + builder.append(locale_id.language_id.language->to_lowercase()); append_sep_and_string(locale_id.language_id.script, Case::Title); append_sep_and_string(locale_id.language_id.region, Case::Upper); diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index 5fc244e5ed1..e570c0e15bc 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -17,25 +17,25 @@ namespace Unicode { struct LanguageID { bool is_root { false }; - Optional language {}; - Optional script {}; - Optional region {}; - Vector variants {}; + Optional language {}; + Optional script {}; + Optional region {}; + Vector variants {}; }; struct Keyword { - StringView key {}; - Vector types {}; + String key {}; + Vector types {}; }; struct LocaleExtension { - Vector attributes {}; + Vector attributes {}; Vector keywords {}; }; struct TransformedField { - StringView key; - Vector values {}; + String key; + Vector values {}; }; struct TransformedExtension { @@ -45,7 +45,7 @@ struct TransformedExtension { struct OtherExtension { char key {}; - Vector values {}; + Vector values {}; }; using Extension = Variant; @@ -53,7 +53,7 @@ using Extension = Variant struct LocaleID { LanguageID language_id {}; Vector extensions {}; - Vector private_use_extensions {}; + Vector private_use_extensions {}; }; // Note: These methods only verify that the provided strings match the EBNF grammar of the