Permalink
Browse files

punycode: Update to v1.0.0

Follow-up to 483edbd, which incorrectly updated the version number,
but not the API, causing a mismatch between the documentation (a2fcc47)
and the actual code.
  • Loading branch information...
1 parent ccc854d commit 9f4277916de44e1ebc311543b396129775dc56bf @mathiasbynens mathiasbynens committed Jun 1, 2012
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/punycode.js
View
@@ -35,8 +35,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'
},
@@ -104,7 +104,7 @@
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/
- function utf16decode(string) {
+ function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
@@ -115,7 +115,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;
}
@@ -126,18 +126,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 Unicode string (UCS-2).
*/
- 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;
@@ -222,7 +221,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,
@@ -313,7 +312,7 @@
}
- return utf16encode(output);
+ return ucs2encode(output);
}
/**
@@ -343,8 +342,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;
@@ -481,9 +480,9 @@
* @memberOf punycode
* @type Object
*/
- 'utf16': {
- 'decode': utf16decode,
- 'encode': utf16encode
+ 'ucs2': {
+ 'decode': ucs2decode,
+ 'encode': ucs2encode
},
'decode': decode,
'encode': encode,

0 comments on commit 9f42779

Please sign in to comment.