Chromium Code Reviews| Index: src/i18n.js |
| diff --git a/src/i18n.js b/src/i18n.js |
| index a64c7e67844b01ebc134956e95c2cba87cd5a288..4b58f84647e289400f38908ae790d8129b344cb6 100644 |
| --- a/src/i18n.js |
| +++ b/src/i18n.js |
| @@ -45,6 +45,11 @@ var AVAILABLE_SERVICES = ['collator', |
| 'dateformat', |
| 'breakiterator']; |
| +var NORMALIZATION_FORMS = ['NFC', |
| + 'NFD', |
| + 'NFKC', |
| + 'NFKD']; |
| + |
| /** |
| * Caches available locales for each service. |
| */ |
| @@ -1988,6 +1993,41 @@ $Object.defineProperty($String.prototype, 'localeCompare', { |
| %FunctionRemovePrototype($String.prototype.localeCompare); |
| %SetNativeFlag($String.prototype.localeCompare); |
| +/** |
| + * Unicode normalization. This method is called with one argument that |
| + * specifies the normalization form. |
| + * If none is specified, "NFC" is assumed. |
| + * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
| + * a RangeError Exception. |
| + * Adds a new method. |
|
Nebojša Ćirić
2013/10/24 19:54:18
Remove * Adds a new method comment. That belongs t
mnita
2013/10/25 15:22:10
Done.
|
| + */ |
| +$Object.defineProperty($String.prototype, 'normalize', { |
| + value: function(that) { |
| + if (%_IsConstructCall()) { |
| + throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| + } |
| + |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw new $TypeError('Method invoked on undefined or null value.'); |
| + } |
| + |
| + var form = $String(%_Arguments(0) || 'NFC'); |
| + |
| + var normForm = NORMALIZATION_FORMS.indexOf(form); |
|
Nebojša Ćirić
2013/10/24 19:54:18
normalizationForm, don't abbreviate (except for lo
mnita
2013/10/25 15:22:10
Done.
|
| + if (normForm !== -1) { |
| + return %StringNormalize(this, normForm); |
| + } |
| + throw new $RangeError('The normalization form should be one of ' |
| + + NORMALIZATION_FORMS.join(', ') + '.'); |
| + }, |
| + writable: true, |
| + configurable: true, |
| + enumerable: false |
| +}); |
| +%FunctionSetName($String.prototype.normalize, 'normalize'); |
| +%FunctionRemovePrototype($String.prototype.normalize); |
| +%SetNativeFlag($String.prototype.normalize); |
| + |
| /** |
| * Formats a Number object (this) using locale and options values. |