Skip to content

Commit

Permalink
punycode: Update to v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens authored and bnoordhuis committed Jan 11, 2012
1 parent c8108aa commit 8abb73e
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions lib/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
/** Error messages */
errors = {
'overflow': 'Overflow: input needs wider integers to process.',
'utf16decode': 'UTF-16(decode): illegal UTF-16 sequence',
'utf16encode': 'UTF-16(encode): illegal UTF-16 value',
'ucs2decode': 'UCS-2(decode): illegal sequence',
'ucs2encode': 'UCS-2(encode): illegal value',
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
'invalid-input': 'Invalid input'
},
Expand Down Expand Up @@ -99,14 +99,13 @@
/**
* Creates an array containing the decimal code points of each character in
* the string.
* @see `punycode.utf16.encode`
* @see <http://tools.ietf.org/html/rfc2781>
* @memberOf punycode.utf16
* @see `punycode.ucs2.encode`
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string.
* @returns {Array} The new array.
*/
function utf16decode(string) {
function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
Expand All @@ -117,7 +116,7 @@
if ((value & 0xF800) == 0xD800) {
extra = string.charCodeAt(counter++);
if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) {
error('utf16decode');
error('ucs2decode');
}
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
}
Expand All @@ -128,18 +127,17 @@

/**
* Creates a string based on an array of decimal code points.
* @see `punycode.utf16.decode`
* @see <http://tools.ietf.org/html/rfc2781>
* @memberOf punycode.utf16
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
* @param {Array} codePoints The array of decimal code points.
* @returns {String} The new string.
*/
function utf16encode(array) {
function ucs2encode(array) {
return map(array, function(value) {
var output = '';
if ((value & 0xF800) == 0xD800) {
error('utf16encode');
error('ucs2encode');
}
if (value > 0xFFFF) {
value -= 0x10000;
Expand Down Expand Up @@ -224,7 +222,7 @@
* @returns {String} The resulting string of Unicode code points.
*/
function decode(input) {
// Don't use UTF-16
// Don't use UCS-2
var output = [],
inputLength = input.length,
out,
Expand Down Expand Up @@ -315,7 +313,7 @@

}

return utf16encode(output);
return ucs2encode(output);
}

/**
Expand Down Expand Up @@ -345,8 +343,8 @@
baseMinusT,
qMinusT;

// Convert the input in UTF-16 to Unicode
input = utf16decode(input);
// Convert the input in UCS-2 to Unicode
input = ucs2decode(input);

// Cache the length
inputLength = input.length;
Expand Down Expand Up @@ -475,16 +473,16 @@
* @memberOf punycode
* @type String
*/
'version': '0.2.1',
'version': '0.3.0',
/**
* An object of methods to convert from JavaScript's internal character
* representation to Unicode and back.
* representation (UCS-2) to Unicode and back.
* @memberOf punycode
* @type Object
*/
'utf16': {
'decode': utf16decode,
'encode': utf16encode
'ucs2': {
'decode': ucs2decode,
'encode': ucs2encode
},
'decode': decode,
'encode': encode,
Expand Down

0 comments on commit 8abb73e

Please sign in to comment.