Skip to content

Commit 8abb73e

Browse files
mathiasbynensbnoordhuis
authored andcommitted
punycode: Update to v0.3.0
1 parent c8108aa commit 8abb73e

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

lib/punycode.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
/** Error messages */
4141
errors = {
4242
'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',
4545
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
4646
'invalid-input': 'Invalid input'
4747
},
@@ -99,14 +99,13 @@
9999
/**
100100
* Creates an array containing the decimal code points of each character in
101101
* 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
105104
* @name decode
106105
* @param {String} string The Unicode input string.
107106
* @returns {Array} The new array.
108107
*/
109-
function utf16decode(string) {
108+
function ucs2decode(string) {
110109
var output = [],
111110
counter = 0,
112111
length = string.length,
@@ -117,7 +116,7 @@
117116
if ((value & 0xF800) == 0xD800) {
118117
extra = string.charCodeAt(counter++);
119118
if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) {
120-
error('utf16decode');
119+
error('ucs2decode');
121120
}
122121
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
123122
}
@@ -128,18 +127,17 @@
128127

129128
/**
130129
* 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
134132
* @name encode
135133
* @param {Array} codePoints The array of decimal code points.
136134
* @returns {String} The new string.
137135
*/
138-
function utf16encode(array) {
136+
function ucs2encode(array) {
139137
return map(array, function(value) {
140138
var output = '';
141139
if ((value & 0xF800) == 0xD800) {
142-
error('utf16encode');
140+
error('ucs2encode');
143141
}
144142
if (value > 0xFFFF) {
145143
value -= 0x10000;
@@ -224,7 +222,7 @@
224222
* @returns {String} The resulting string of Unicode code points.
225223
*/
226224
function decode(input) {
227-
// Don't use UTF-16
225+
// Don't use UCS-2
228226
var output = [],
229227
inputLength = input.length,
230228
out,
@@ -315,7 +313,7 @@
315313

316314
}
317315

318-
return utf16encode(output);
316+
return ucs2encode(output);
319317
}
320318

321319
/**
@@ -345,8 +343,8 @@
345343
baseMinusT,
346344
qMinusT;
347345

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);
350348

351349
// Cache the length
352350
inputLength = input.length;
@@ -475,16 +473,16 @@
475473
* @memberOf punycode
476474
* @type String
477475
*/
478-
'version': '0.2.1',
476+
'version': '0.3.0',
479477
/**
480478
* 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.
482480
* @memberOf punycode
483481
* @type Object
484482
*/
485-
'utf16': {
486-
'decode': utf16decode,
487-
'encode': utf16encode
483+
'ucs2': {
484+
'decode': ucs2decode,
485+
'encode': ucs2encode
488486
},
489487
'decode': decode,
490488
'encode': encode,

0 commit comments

Comments
 (0)