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 | |
39 // null is typeof 'object' so we have to do extra check. | 37 // null is typeof 'object' so we have to do extra check. |
40 if (typeof localeID !== 'string' && typeof localeID !== 'object' || | 38 if (typeof localeID !== 'string' && typeof localeID !== 'object' || |
41 localeID === null) { | 39 localeID === null) { |
42 throw new TypeError('Language ID should be string or object.'); | 40 throw new TypeError('Language ID should be string or object.'); |
43 } | 41 } |
44 | 42 |
45 var localeString = String(localeID); | 43 var localeString = String(localeID); |
46 | 44 |
47 if (isValidLanguageTag(localeString) === false) { | 45 if (isValidLanguageTag(localeString) === false) { |
48 throw new RangeError('Invalid language tag: ' + localeString); | 46 throw new RangeError('Invalid language tag: ' + localeString); |
49 } | 47 } |
50 | 48 |
51 // This call will strip -kn but not -kn-true extensions. | 49 // This call will strip -kn but not -kn-true extensions. |
52 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. | 50 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. |
53 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after | 51 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after |
54 // upgrade to ICU 4.9. | 52 // upgrade to ICU 4.9. |
55 var tag = NativeJSCanonicalizeLanguageTag(localeString); | 53 var tag = %CanonicalizeLanguageTag(localeString); |
56 if (tag === 'invalid-tag') { | 54 if (tag === 'invalid-tag') { |
57 throw new RangeError('Invalid language tag: ' + localeString); | 55 throw new RangeError('Invalid language tag: ' + localeString); |
58 } | 56 } |
59 | 57 |
60 return tag; | 58 return tag; |
61 } | 59 } |
62 | 60 |
63 | 61 |
64 /** | 62 /** |
65 * Returns an array where all locales are canonicalized and duplicates removed. | 63 * Returns an array where all locales are canonicalized and duplicates removed. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})'; | 181 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})'; |
184 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + | 182 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + |
185 alpha + '{5,8})'; | 183 alpha + '{5,8})'; |
186 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + | 184 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + |
187 variant + ')*(-' + extension + ')*(-' + privateUse + ')?'; | 185 variant + ')*(-' + extension + ')*(-' + privateUse + ')?'; |
188 | 186 |
189 var languageTag = | 187 var languageTag = |
190 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; | 188 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; |
191 LANGUAGE_TAG_RE = new RegExp(languageTag, 'i'); | 189 LANGUAGE_TAG_RE = new RegExp(languageTag, 'i'); |
192 })(); | 190 })(); |
OLD | NEW |