punycode: Update to v0.3.0
This commit is contained in:
parent
c8108aad83
commit
8abb73ef58
@ -40,8 +40,8 @@
|
|||||||
/** Error messages */
|
/** Error messages */
|
||||||
errors = {
|
errors = {
|
||||||
'overflow': 'Overflow: input needs wider integers to process.',
|
'overflow': 'Overflow: input needs wider integers to process.',
|
||||||
'utf16decode': 'UTF-16(decode): illegal UTF-16 sequence',
|
'ucs2decode': 'UCS-2(decode): illegal sequence',
|
||||||
'utf16encode': 'UTF-16(encode): illegal UTF-16 value',
|
'ucs2encode': 'UCS-2(encode): illegal value',
|
||||||
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
||||||
'invalid-input': 'Invalid input'
|
'invalid-input': 'Invalid input'
|
||||||
},
|
},
|
||||||
@ -99,14 +99,13 @@
|
|||||||
/**
|
/**
|
||||||
* Creates an array containing the decimal code points of each character in
|
* Creates an array containing the decimal code points of each character in
|
||||||
* the string.
|
* the string.
|
||||||
* @see `punycode.utf16.encode`
|
* @see `punycode.ucs2.encode`
|
||||||
* @see <http://tools.ietf.org/html/rfc2781>
|
* @memberOf punycode.ucs2
|
||||||
* @memberOf punycode.utf16
|
|
||||||
* @name decode
|
* @name decode
|
||||||
* @param {String} string The Unicode input string.
|
* @param {String} string The Unicode input string.
|
||||||
* @returns {Array} The new array.
|
* @returns {Array} The new array.
|
||||||
*/
|
*/
|
||||||
function utf16decode(string) {
|
function ucs2decode(string) {
|
||||||
var output = [],
|
var output = [],
|
||||||
counter = 0,
|
counter = 0,
|
||||||
length = string.length,
|
length = string.length,
|
||||||
@ -117,7 +116,7 @@
|
|||||||
if ((value & 0xF800) == 0xD800) {
|
if ((value & 0xF800) == 0xD800) {
|
||||||
extra = string.charCodeAt(counter++);
|
extra = string.charCodeAt(counter++);
|
||||||
if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) {
|
if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) {
|
||||||
error('utf16decode');
|
error('ucs2decode');
|
||||||
}
|
}
|
||||||
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
|
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
|
||||||
}
|
}
|
||||||
@ -128,18 +127,17 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a string based on an array of decimal code points.
|
* Creates a string based on an array of decimal code points.
|
||||||
* @see `punycode.utf16.decode`
|
* @see `punycode.ucs2.decode`
|
||||||
* @see <http://tools.ietf.org/html/rfc2781>
|
* @memberOf punycode.ucs2
|
||||||
* @memberOf punycode.utf16
|
|
||||||
* @name encode
|
* @name encode
|
||||||
* @param {Array} codePoints The array of decimal code points.
|
* @param {Array} codePoints The array of decimal code points.
|
||||||
* @returns {String} The new string.
|
* @returns {String} The new string.
|
||||||
*/
|
*/
|
||||||
function utf16encode(array) {
|
function ucs2encode(array) {
|
||||||
return map(array, function(value) {
|
return map(array, function(value) {
|
||||||
var output = '';
|
var output = '';
|
||||||
if ((value & 0xF800) == 0xD800) {
|
if ((value & 0xF800) == 0xD800) {
|
||||||
error('utf16encode');
|
error('ucs2encode');
|
||||||
}
|
}
|
||||||
if (value > 0xFFFF) {
|
if (value > 0xFFFF) {
|
||||||
value -= 0x10000;
|
value -= 0x10000;
|
||||||
@ -224,7 +222,7 @@
|
|||||||
* @returns {String} The resulting string of Unicode code points.
|
* @returns {String} The resulting string of Unicode code points.
|
||||||
*/
|
*/
|
||||||
function decode(input) {
|
function decode(input) {
|
||||||
// Don't use UTF-16
|
// Don't use UCS-2
|
||||||
var output = [],
|
var output = [],
|
||||||
inputLength = input.length,
|
inputLength = input.length,
|
||||||
out,
|
out,
|
||||||
@ -315,7 +313,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return utf16encode(output);
|
return ucs2encode(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,8 +343,8 @@
|
|||||||
baseMinusT,
|
baseMinusT,
|
||||||
qMinusT;
|
qMinusT;
|
||||||
|
|
||||||
// Convert the input in UTF-16 to Unicode
|
// Convert the input in UCS-2 to Unicode
|
||||||
input = utf16decode(input);
|
input = ucs2decode(input);
|
||||||
|
|
||||||
// Cache the length
|
// Cache the length
|
||||||
inputLength = input.length;
|
inputLength = input.length;
|
||||||
@ -475,16 +473,16 @@
|
|||||||
* @memberOf punycode
|
* @memberOf punycode
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
'version': '0.2.1',
|
'version': '0.3.0',
|
||||||
/**
|
/**
|
||||||
* An object of methods to convert from JavaScript's internal character
|
* 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
|
* @memberOf punycode
|
||||||
* @type Object
|
* @type Object
|
||||||
*/
|
*/
|
||||||
'utf16': {
|
'ucs2': {
|
||||||
'decode': utf16decode,
|
'decode': ucs2decode,
|
||||||
'encode': utf16encode
|
'encode': ucs2encode
|
||||||
},
|
},
|
||||||
'decode': decode,
|
'decode': decode,
|
||||||
'encode': encode,
|
'encode': encode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user