[Intl] Move LookupUnicodeExtensions to Intl
Bug: v8:5751 Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng Change-Id: I67e15208bc2954957275e3283eb746c1c12f10f0 Reviewed-on: https://chromium-review.googlesource.com/1191362 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#55436}
This commit is contained in:
parent
1113edd32a
commit
812c0acd9a
@ -2467,5 +2467,52 @@ MaybeHandle<JSObject> Intl::SupportedLocalesOf(Isolate* isolate,
|
||||
requested_locales, options_in);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Intl::LookupUnicodeExtensions(
|
||||
const icu::Locale& icu_locale, const std::set<std::string>& relevant_keys) {
|
||||
std::map<std::string, std::string> extensions;
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::StringEnumeration> keywords(
|
||||
icu_locale.createKeywords(status));
|
||||
if (U_FAILURE(status)) return extensions;
|
||||
|
||||
if (!keywords) return extensions;
|
||||
char value[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
int32_t length;
|
||||
status = U_ZERO_ERROR;
|
||||
for (const char* keyword = keywords->next(&length, status);
|
||||
keyword != nullptr; keyword = keywords->next(&length, status)) {
|
||||
// Ignore failures in ICU and skip to the next keyword.
|
||||
//
|
||||
// This is fine.™
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
icu_locale.getKeywordValue(keyword, value, ULOC_FULLNAME_CAPACITY, status);
|
||||
|
||||
// Ignore failures in ICU and skip to the next keyword.
|
||||
//
|
||||
// This is fine.™
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* bcp47_key = uloc_toUnicodeLocaleKey(keyword);
|
||||
|
||||
// Ignore keywords that we don't recognize - spec allows that.
|
||||
if (bcp47_key && (relevant_keys.find(bcp47_key) != relevant_keys.end())) {
|
||||
const char* bcp47_value = uloc_toUnicodeLocaleType(bcp47_key, value);
|
||||
extensions.insert(
|
||||
std::pair<std::string, std::string>(bcp47_key, bcp47_value));
|
||||
}
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -434,6 +434,10 @@ class Intl {
|
||||
Handle<String> field_type_string, Handle<String> value,
|
||||
Handle<String> additional_property_name,
|
||||
Handle<String> additional_property_value);
|
||||
|
||||
// A helper function to help handle Unicode Extensions in locale.
|
||||
static std::map<std::string, std::string> LookupUnicodeExtensions(
|
||||
const icu::Locale& icu_locale, const std::set<std::string>& relevant_keys);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -172,53 +172,6 @@ Handle<JSObject> JSCollator::ResolvedOptions(Isolate* isolate,
|
||||
|
||||
namespace {
|
||||
|
||||
std::map<std::string, std::string> LookupUnicodeExtensions(
|
||||
const icu::Locale& icu_locale, const std::set<std::string>& relevant_keys) {
|
||||
std::map<std::string, std::string> extensions;
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::StringEnumeration> keywords(
|
||||
icu_locale.createKeywords(status));
|
||||
if (U_FAILURE(status)) return extensions;
|
||||
|
||||
if (!keywords) return extensions;
|
||||
char value[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
int32_t length;
|
||||
status = U_ZERO_ERROR;
|
||||
for (const char* keyword = keywords->next(&length, status);
|
||||
keyword != nullptr; keyword = keywords->next(&length, status)) {
|
||||
// Ignore failures in ICU and skip to the next keyword.
|
||||
//
|
||||
// This is fine.™
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
icu_locale.getKeywordValue(keyword, value, ULOC_FULLNAME_CAPACITY, status);
|
||||
|
||||
// Ignore failures in ICU and skip to the next keyword.
|
||||
//
|
||||
// This is fine.™
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* bcp47_key = uloc_toUnicodeLocaleKey(keyword);
|
||||
|
||||
// Ignore keywords that we don't recognize - spec allows that.
|
||||
if (bcp47_key && (relevant_keys.find(bcp47_key) != relevant_keys.end())) {
|
||||
const char* bcp47_value = uloc_toUnicodeLocaleType(bcp47_key, value);
|
||||
extensions.insert(
|
||||
std::pair<std::string, std::string>(bcp47_key, bcp47_value));
|
||||
}
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
void SetCaseFirstOption(icu::Collator* icu_collator, const char* value) {
|
||||
CHECK_NOT_NULL(icu_collator);
|
||||
CHECK_NOT_NULL(value);
|
||||
@ -368,7 +321,7 @@ MaybeHandle<JSCollator> JSCollator::InitializeCollator(
|
||||
DCHECK(!icu_locale.isBogus());
|
||||
|
||||
std::map<std::string, std::string> extensions =
|
||||
LookupUnicodeExtensions(icu_locale, relevant_extension_keys);
|
||||
Intl::LookupUnicodeExtensions(icu_locale, relevant_extension_keys);
|
||||
|
||||
// 19. Let collation be r.[[co]].
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user