OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 16 matching lines...) Expand all Loading... |
27 // limitations under the License. | 27 // limitations under the License. |
28 | 28 |
29 // ECMAScript 402 API implementation is broken into separate files for | 29 // ECMAScript 402 API implementation is broken into separate files for |
30 // each service. The build system combines them together into one | 30 // each service. The build system combines them together into one |
31 // Intl namespace. | 31 // Intl namespace. |
32 | 32 |
33 /** | 33 /** |
34 * Canonicalizes the language tag, or throws in case the tag is invalid. | 34 * Canonicalizes the language tag, or throws in case the tag is invalid. |
35 */ | 35 */ |
36 function canonicalizeLanguageTag(localeID) { | 36 function canonicalizeLanguageTag(localeID) { |
| 37 native function NativeJSCanonicalizeLanguageTag(); |
| 38 |
37 // null is typeof 'object' so we have to do extra check. | 39 // null is typeof 'object' so we have to do extra check. |
38 if (typeof localeID !== 'string' && typeof localeID !== 'object' || | 40 if (typeof localeID !== 'string' && typeof localeID !== 'object' || |
39 localeID === null) { | 41 localeID === null) { |
40 throw new TypeError('Language ID should be string or object.'); | 42 throw new TypeError('Language ID should be string or object.'); |
41 } | 43 } |
42 | 44 |
43 var localeString = String(localeID); | 45 var localeString = String(localeID); |
44 | 46 |
45 if (isValidLanguageTag(localeString) === false) { | 47 if (isValidLanguageTag(localeString) === false) { |
46 throw new RangeError('Invalid language tag: ' + localeString); | 48 throw new RangeError('Invalid language tag: ' + localeString); |
47 } | 49 } |
48 | 50 |
49 // This call will strip -kn but not -kn-true extensions. | 51 // This call will strip -kn but not -kn-true extensions. |
50 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. | 52 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. |
51 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after | 53 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after |
52 // upgrade to ICU 4.9. | 54 // upgrade to ICU 4.9. |
53 var tag = %CanonicalizeLanguageTag(localeString); | 55 var tag = NativeJSCanonicalizeLanguageTag(localeString); |
54 if (tag === 'invalid-tag') { | 56 if (tag === 'invalid-tag') { |
55 throw new RangeError('Invalid language tag: ' + localeString); | 57 throw new RangeError('Invalid language tag: ' + localeString); |
56 } | 58 } |
57 | 59 |
58 return tag; | 60 return tag; |
59 } | 61 } |
60 | 62 |
61 | 63 |
62 /** | 64 /** |
63 * Returns an array where all locales are canonicalized and duplicates removed. | 65 * Returns an array where all locales are canonicalized and duplicates removed. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})'; | 183 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})'; |
182 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + | 184 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + |
183 alpha + '{5,8})'; | 185 alpha + '{5,8})'; |
184 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + | 186 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + |
185 variant + ')*(-' + extension + ')*(-' + privateUse + ')?'; | 187 variant + ')*(-' + extension + ')*(-' + privateUse + ')?'; |
186 | 188 |
187 var languageTag = | 189 var languageTag = |
188 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; | 190 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; |
189 LANGUAGE_TAG_RE = new RegExp(languageTag, 'i'); | 191 LANGUAGE_TAG_RE = new RegExp(languageTag, 'i'); |
190 })(); | 192 })(); |
OLD | NEW |