Commit 9acf5f41 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Use setUnicodeKeywordValue instead of setKeywordValue

Bug: v8:8318
Change-Id: I1c4bb26270c4ea9ede99a131f804568e6f721fc6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1560657Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60756}
parent b29993f4
......@@ -1556,7 +1556,8 @@ std::map<std::string, std::string> LookupAndValidateUnicodeExtensions(
}
}
status = U_ZERO_ERROR;
icu_locale->setKeywordValue(keyword, nullptr, status);
icu_locale->setUnicodeKeywordValue(
bcp47_key == nullptr ? keyword : bcp47_key, nullptr, status);
CHECK(U_SUCCESS(status));
}
......
......@@ -134,22 +134,13 @@ Handle<JSObject> JSCollator::ResolvedOptions(Isolate* isolate,
const char* collation = "default";
const char* usage = "sort";
const char* collation_key = "co";
const char* legacy_collation_key = uloc_toLegacyKey(collation_key);
DCHECK_NOT_NULL(legacy_collation_key);
char legacy_collation_value[ULOC_FULLNAME_CAPACITY];
status = U_ZERO_ERROR;
int32_t length =
icu_locale.getKeywordValue(legacy_collation_key, legacy_collation_value,
ULOC_FULLNAME_CAPACITY, status);
std::string collation_value =
icu_locale.getUnicodeKeywordValue<std::string>(collation_key, status);
std::string locale;
if (length > 0 && U_SUCCESS(status)) {
const char* collation_value =
uloc_toUnicodeLocaleType(collation_key, legacy_collation_value);
CHECK_NOT_NULL(collation_value);
if (strcmp(collation_value, "search") == 0) {
if (U_SUCCESS(status)) {
if (collation_value == "search") {
usage = "search";
// Search is disallowed as a collation value per spec. Let's
......@@ -166,12 +157,12 @@ Handle<JSObject> JSCollator::ResolvedOptions(Isolate* isolate,
// The spec forbids the search as a collation value in the
// locale tag, so let's filter it out.
status = U_ZERO_ERROR;
new_icu_locale.setKeywordValue(legacy_collation_key, nullptr, status);
new_icu_locale.setUnicodeKeywordValue(collation_key, nullptr, status);
CHECK(U_SUCCESS(status));
locale = Intl::ToLanguageTag(new_icu_locale).FromJust();
} else {
collation = collation_value;
collation = collation_value.c_str();
locale = Intl::ToLanguageTag(icu_locale).FromJust();
}
} else {
......@@ -348,12 +339,8 @@ MaybeHandle<JSCollator> JSCollator::Initialize(Isolate* isolate,
// This will need to be filtered out when creating the
// resolvedOptions object.
if (usage == Usage::SEARCH) {
const char* key = uloc_toLegacyKey("co");
CHECK_NOT_NULL(key);
const char* value = uloc_toLegacyType(key, "search");
CHECK_NOT_NULL(value);
UErrorCode status = U_ZERO_ERROR;
icu_locale.setKeywordValue(key, value, status);
icu_locale.setUnicodeKeywordValue("co", "search", status);
CHECK(U_SUCCESS(status));
}
......
......@@ -1435,7 +1435,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
Intl::ToHourCycle(hc_extension_it->second.c_str())) {
// Remove -hc- if it does not agree with what we used.
UErrorCode status = U_ZERO_ERROR;
icu_locale.setKeywordValue(uloc_toLegacyKey("hc"), nullptr, status);
icu_locale.setUnicodeKeywordValue("hc", nullptr, status);
CHECK(U_SUCCESS(status));
}
}
......
......@@ -98,15 +98,12 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate,
}
DCHECK_NOT_NULL(value_str.get());
// Convert bcp47 key and value into legacy ICU format so we can use
// uloc_setKeywordValue.
const char* key = uloc_toLegacyKey(option_to_bcp47.key);
DCHECK_NOT_NULL(key);
// Overwrite existing, or insert new key-value to the locale string.
const char* value = uloc_toLegacyType(key, value_str.get());
if (value) {
icu_locale->setKeywordValue(key, value, status);
if (uloc_toLegacyType(uloc_toLegacyKey(option_to_bcp47.key),
value_str.get())) {
// Only call setUnicodeKeywordValue if that value is a valid one.
icu_locale->setUnicodeKeywordValue(option_to_bcp47.key, value_str.get(),
status);
if (U_FAILURE(status)) {
return Just(false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment