Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Unified Diff: src/js/i18n.js

Issue 1812673005: Use ICU case conversion/transliterator for case conversion behind a flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use transliterator for case conversion of Greek/Lithuanian Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/js/i18n.js
diff --git a/src/js/i18n.js b/src/js/i18n.js
index 845289a91f10cf1416c4cff4b6698e27f412d6be..a2a0029b76c34cf48067dfe0c57f5f14c4489d74 100644
--- a/src/js/i18n.js
+++ b/src/js/i18n.js
@@ -144,6 +144,13 @@ var AVAILABLE_LOCALES = {
*/
var DEFAULT_ICU_LOCALE = UNDEFINED;
+function GetDefaultICULocaleJS() {
+ if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
+ DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
+ }
+ return DEFAULT_ICU_LOCALE;
+}
+
/**
* Unicode extension regular expression.
*/
@@ -448,11 +455,7 @@ function lookupMatcher(service, requestedLocales) {
}
// Didn't find a match, return default.
- if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
- DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
- }
-
- return {'locale': DEFAULT_ICU_LOCALE, 'extension': '', 'position': -1};
+ return {'locale': GetDefaultICULocaleJS(), 'extension': '', 'position': -1};
}
@@ -1992,6 +1995,23 @@ function cachedOrNewService(service, locales, options, defaults) {
return new savedObjects[service](locales, useOptions);
}
+function getCaseConversionLanguageId(locales) {
+ var locales = initializeLocaleList(locales);
+ var language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS();
+ var pos = %_Call(StringIndexOf, language, '-');
+ if (pos != -1)
+ language = %_Call(StringSubstring, language, 0, pos);
+ var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr'];
+ return %_Call(ArrayIndexOf, CUSTOM_CASE_LANGUAGES, language);
+}
+
+function localeConvertCase(s, locales, isToUpper) {
+ var caseConversionLanguageId = getCaseConversionLanguageId(locales);
+ if (caseConversionLanguageId == -1)
+ return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s);
+ return %StringLocaleConvertCase(s, isToUpper, caseConversionLanguageId);
+}
+
/**
* Compares this and that, and returns less than 0, 0 or greater than 0 value.
* Overrides the built-in method.
@@ -2044,6 +2064,45 @@ OverrideFunction(GlobalString.prototype, 'normalize', function() {
}
);
+OverrideFunction(GlobalString.prototype, 'toLowerCase', function() {
+ if (!IS_UNDEFINED(new.target)) {
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
+ }
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
+ var s = TO_STRING(this);
+ return %StringToLowerCaseI18N(s);
+ }
+);
+
+OverrideFunction(GlobalString.prototype, 'toUpperCase', function() {
+ if (!IS_UNDEFINED(new.target)) {
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
+ }
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
+ var s = TO_STRING(this);
+ return %StringToUpperCaseI18N(s);
+ }
+);
+
+OverrideFunction(GlobalString.prototype, 'toLocaleLowerCase', function() {
+ if (!IS_UNDEFINED(new.target)) {
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
+ }
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
+ return localeConvertCase(TO_STRING(this), arguments[0], false);
+ }
+);
+
+
+OverrideFunction(GlobalString.prototype, 'toLocaleUpperCase', function() {
+ if (!IS_UNDEFINED(new.target)) {
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
+ }
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
+ return localeConvertCase(TO_STRING(this), arguments[0], true);
+ }
+);
+
/**
* Formats a Number object (this) using locale and options values.
« no previous file with comments | « src/flag-definitions.h ('k') | src/runtime/runtime.h » ('j') | src/runtime/runtime-i18n.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698