summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Bynens <mathias@qiwi.be>2013-06-20 12:40:44 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-06-20 13:02:53 +0200
commit24ba9fdec8c4ba0fd367aef4a3f266f69d8655aa (patch)
tree3f2357623fa50446a0a3a51794e4998e5f5cbbad
parentf5e13ae9b5ca6eaacbcf9aad36552d9cd6c8bde6 (diff)
downloadandroid-node-v8-24ba9fdec8c4ba0fd367aef4a3f266f69d8655aa.tar.gz
android-node-v8-24ba9fdec8c4ba0fd367aef4a3f266f69d8655aa.tar.bz2
android-node-v8-24ba9fdec8c4ba0fd367aef4a3f266f69d8655aa.zip
punycode: update to v1.2.3
-rw-r--r--lib/punycode.js110
1 files changed, 54 insertions, 56 deletions
diff --git a/lib/punycode.js b/lib/punycode.js
index 163923c40f..41803ba423 100644
--- a/lib/punycode.js
+++ b/lib/punycode.js
@@ -1,6 +1,15 @@
-/*! http://mths.be/punycode v1.2.0 by @mathias */
+/*! http://mths.be/punycode v1.2.3 by @mathias */
;(function(root) {
+ /** Detect free variables */
+ var freeExports = typeof exports == 'object' && exports;
+ var freeModule = typeof module == 'object' && module &&
+ module.exports == freeExports && module;
+ var freeGlobal = typeof global == 'object' && global;
+ if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
+ root = freeGlobal;
+ }
+
/**
* The `punycode` object.
* @name punycode
@@ -8,13 +17,6 @@
*/
var punycode,
- /** Detect free variables `define`, `exports`, `module` and `require` */
- freeDefine = typeof define == 'function' && typeof define.amd == 'object' &&
- define.amd && define,
- freeExports = typeof exports == 'object' && exports,
- freeModule = typeof module == 'object' && module,
- freeRequire = typeof require == 'function' && require,
-
/** Highest positive signed 32-bit float value */
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
@@ -90,7 +92,7 @@
}
/**
- * Creates an array containing the decimal code points of each Unicode
+ * Creates an array containing the numeric code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
@@ -110,13 +112,16 @@
extra;
while (counter < length) {
value = string.charCodeAt(counter++);
- if ((value & 0xF800) == 0xD800 && counter < length) {
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
- output.push(value, extra);
+ // unmatched surrogate; only append this code unit, in case the next
+ // code unit is the high surrogate of a surrogate pair
+ output.push(value);
+ counter--;
}
} else {
output.push(value);
@@ -126,11 +131,11 @@
}
/**
- * Creates a string based on an array of decimal code points.
+ * Creates a string based on an array of numeric code points.
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
- * @param {Array} codePoints The array of decimal code points.
+ * @param {Array} codePoints The array of numeric code points.
* @returns {String} The new Unicode string (UCS-2).
*/
function ucs2encode(array) {
@@ -150,19 +155,22 @@
* Converts a basic code point into a digit/integer.
* @see `digitToBasic()`
* @private
- * @param {Number} codePoint The basic (decimal) code point.
+ * @param {Number} codePoint The basic numeric code point value.
* @returns {Number} The numeric value of a basic code point (for use in
* representing integers) in the range `0` to `base - 1`, or `base` if
* the code point does not represent a value.
*/
function basicToDigit(codePoint) {
- return codePoint - 48 < 10
- ? codePoint - 22
- : codePoint - 65 < 26
- ? codePoint - 65
- : codePoint - 97 < 26
- ? codePoint - 97
- : base;
+ if (codePoint - 48 < 10) {
+ return codePoint - 22;
+ }
+ if (codePoint - 65 < 26) {
+ return codePoint - 65;
+ }
+ if (codePoint - 97 < 26) {
+ return codePoint - 97;
+ }
+ return base;
}
/**
@@ -174,7 +182,7 @@
* representing integers) is `digit`, which needs to be in the range
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
* used; else, the lowercase form is used. The behavior is undefined
- * if flag is non-zero and `digit` has no uppercase form.
+ * if `flag` is non-zero and `digit` has no uppercase form.
*/
function digitToBasic(digit, flag) {
// 0..25 map to ASCII a..z or A..Z
@@ -198,25 +206,11 @@
}
/**
- * Converts a basic code point to lowercase if `flag` is falsy, or to
- * uppercase if `flag` is truthy. The code point is unchanged if it's
- * caseless. The behavior is undefined if `codePoint` is not a basic code
- * point.
- * @private
- * @param {Number} codePoint The numeric value of a basic code point.
- * @returns {Number} The resulting basic code point.
- */
- function encodeBasic(codePoint, flag) {
- codePoint -= (codePoint - 97 < 26) << 5;
- return codePoint + (!flag && codePoint - 65 < 26) << 5;
- }
-
- /**
- * Converts a Punycode string of ASCII code points to a string of Unicode
- * code points.
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
+ * symbols.
* @memberOf punycode
- * @param {String} input The Punycode string of ASCII code points.
- * @returns {String} The resulting string of Unicode code points.
+ * @param {String} input The Punycode string of ASCII-only symbols.
+ * @returns {String} The resulting string of Unicode symbols.
*/
function decode(input) {
// Don't use UCS-2
@@ -314,11 +308,11 @@
}
/**
- * Converts a string of Unicode code points to a Punycode string of ASCII
- * code points.
+ * Converts a string of Unicode symbols to a Punycode string of ASCII-only
+ * symbols.
* @memberOf punycode
- * @param {String} input The string of Unicode code points.
- * @returns {String} The resulting Punycode string of ASCII code points.
+ * @param {String} input The string of Unicode symbols.
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
*/
function encode(input) {
var n,
@@ -470,10 +464,10 @@
* @memberOf punycode
* @type String
*/
- 'version': '1.2.0',
+ 'version': '1.2.3',
/**
* An object of methods to convert from JavaScript's internal character
- * representation (UCS-2) to decimal Unicode code points, and back.
+ * representation (UCS-2) to Unicode code points, and back.
* @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode
* @type Object
@@ -489,21 +483,25 @@
};
/** Expose `punycode` */
- if (freeExports) {
- if (freeModule && freeModule.exports == freeExports) {
- // in Node.js or Ringo 0.8+
+ // Some AMD build optimizers, like r.js, check for specific condition patterns
+ // like the following:
+ if (
+ typeof define == 'function' &&
+ typeof define.amd == 'object' &&
+ define.amd
+ ) {
+ define(function() {
+ return punycode;
+ });
+ } else if (freeExports && !freeExports.nodeType) {
+ if (freeModule) { // in Node.js or RingoJS v0.8.0+
freeModule.exports = punycode;
- } else {
- // in Narwhal or Ringo 0.7-
+ } else { // in Narwhal or RingoJS v0.7.0-
for (key in punycode) {
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
}
}
- } else if (freeDefine) {
- // via curl.js or RequireJS
- define('punycode', punycode);
- } else {
- // in a browser or Rhino
+ } else { // in Rhino or a web browser
root.punycode = punycode;
}