|
40 | 40 | /** Error messages */ |
41 | 41 | errors = { |
42 | 42 | 'overflow': 'Overflow: input needs wider integers to process.', |
43 | | - 'utf16decode': 'UTF-16(decode): illegal UTF-16 sequence', |
44 | | - 'utf16encode': 'UTF-16(encode): illegal UTF-16 value', |
| 43 | + 'ucs2decode': 'UCS-2(decode): illegal sequence', |
| 44 | + 'ucs2encode': 'UCS-2(encode): illegal value', |
45 | 45 | 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', |
46 | 46 | 'invalid-input': 'Invalid input' |
47 | 47 | }, |
|
99 | 99 | /** |
100 | 100 | * Creates an array containing the decimal code points of each character in |
101 | 101 | * the string. |
102 | | - * @see `punycode.utf16.encode` |
103 | | - * @see <http://tools.ietf.org/html/rfc2781> |
104 | | - * @memberOf punycode.utf16 |
| 102 | + * @see `punycode.ucs2.encode` |
| 103 | + * @memberOf punycode.ucs2 |
105 | 104 | * @name decode |
106 | 105 | * @param {String} string The Unicode input string. |
107 | 106 | * @returns {Array} The new array. |
108 | 107 | */ |
109 | | - function utf16decode(string) { |
| 108 | + function ucs2decode(string) { |
110 | 109 | var output = [], |
111 | 110 | counter = 0, |
112 | 111 | length = string.length, |
|
117 | 116 | if ((value & 0xF800) == 0xD800) { |
118 | 117 | extra = string.charCodeAt(counter++); |
119 | 118 | if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) { |
120 | | - error('utf16decode'); |
| 119 | + error('ucs2decode'); |
121 | 120 | } |
122 | 121 | value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000; |
123 | 122 | } |
|
128 | 127 |
|
129 | 128 | /** |
130 | 129 | * Creates a string based on an array of decimal code points. |
131 | | - * @see `punycode.utf16.decode` |
132 | | - * @see <http://tools.ietf.org/html/rfc2781> |
133 | | - * @memberOf punycode.utf16 |
| 130 | + * @see `punycode.ucs2.decode` |
| 131 | + * @memberOf punycode.ucs2 |
134 | 132 | * @name encode |
135 | 133 | * @param {Array} codePoints The array of decimal code points. |
136 | 134 | * @returns {String} The new string. |
137 | 135 | */ |
138 | | - function utf16encode(array) { |
| 136 | + function ucs2encode(array) { |
139 | 137 | return map(array, function(value) { |
140 | 138 | var output = ''; |
141 | 139 | if ((value & 0xF800) == 0xD800) { |
142 | | - error('utf16encode'); |
| 140 | + error('ucs2encode'); |
143 | 141 | } |
144 | 142 | if (value > 0xFFFF) { |
145 | 143 | value -= 0x10000; |
|
224 | 222 | * @returns {String} The resulting string of Unicode code points. |
225 | 223 | */ |
226 | 224 | function decode(input) { |
227 | | - // Don't use UTF-16 |
| 225 | + // Don't use UCS-2 |
228 | 226 | var output = [], |
229 | 227 | inputLength = input.length, |
230 | 228 | out, |
|
315 | 313 |
|
316 | 314 | } |
317 | 315 |
|
318 | | - return utf16encode(output); |
| 316 | + return ucs2encode(output); |
319 | 317 | } |
320 | 318 |
|
321 | 319 | /** |
|
345 | 343 | baseMinusT, |
346 | 344 | qMinusT; |
347 | 345 |
|
348 | | - // Convert the input in UTF-16 to Unicode |
349 | | - input = utf16decode(input); |
| 346 | + // Convert the input in UCS-2 to Unicode |
| 347 | + input = ucs2decode(input); |
350 | 348 |
|
351 | 349 | // Cache the length |
352 | 350 | inputLength = input.length; |
|
475 | 473 | * @memberOf punycode |
476 | 474 | * @type String |
477 | 475 | */ |
478 | | - 'version': '0.2.1', |
| 476 | + 'version': '0.3.0', |
479 | 477 | /** |
480 | 478 | * An object of methods to convert from JavaScript's internal character |
481 | | - * representation to Unicode and back. |
| 479 | + * representation (UCS-2) to Unicode and back. |
482 | 480 | * @memberOf punycode |
483 | 481 | * @type Object |
484 | 482 | */ |
485 | | - 'utf16': { |
486 | | - 'decode': utf16decode, |
487 | | - 'encode': utf16encode |
| 483 | + 'ucs2': { |
| 484 | + 'decode': ucs2decode, |
| 485 | + 'encode': ucs2encode |
488 | 486 | }, |
489 | 487 | 'decode': decode, |
490 | 488 | 'encode': encode, |
|
0 commit comments