diff options
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/punycode2/ucs2/decode.js')
-rw-r--r-- | bin/wiki/ImportarDesdeURL/node_modules/punycode2/ucs2/decode.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/punycode2/ucs2/decode.js b/bin/wiki/ImportarDesdeURL/node_modules/punycode2/ucs2/decode.js new file mode 100644 index 00000000..08af0d18 --- /dev/null +++ b/bin/wiki/ImportarDesdeURL/node_modules/punycode2/ucs2/decode.js @@ -0,0 +1,40 @@ +'use strict'; + +/** + * 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, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see <https://mathiasbynens.be/notes/javascript-encoding> + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. +*/ +module.exports = function ucs2decode(string) { + var output = [], + counter = 0, + length = string.length, + value, + extra; + while (counter < length) { + value = string.charCodeAt(counter++); + 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 { + // 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); + } + } + return output; +}; |