* `ucs2decode` function from the punycode.js library. * * Creates an array containing the decimal 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 se
(string)
| 43 | */ |
| 44 | |
| 45 | function decode (string) { |
| 46 | const output = [] |
| 47 | let counter = 0 |
| 48 | const length = string.length |
| 49 | |
| 50 | while (counter < length) { |
| 51 | const value = string.charCodeAt(counter++) |
| 52 | |
| 53 | if (value >= 0xD800 && value <= 0xDBFF && counter < length) { |
| 54 | |
| 55 | // It's a high surrogate, and there is a next character. |
| 56 | |
| 57 | const extra = string.charCodeAt(counter++) |
| 58 | |
| 59 | if ((extra & 0xFC00) == 0xDC00) { // Low surrogate. |
| 60 | output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000) |
| 61 | } else { |
| 62 | |
| 63 | // It's an unmatched surrogate; only append this code unit, in case the |
| 64 | // next code unit is the high surrogate of a surrogate pair. |
| 65 | |
| 66 | output.push(value) |
| 67 | counter-- |
| 68 | } |
| 69 | } else { |
| 70 | output.push(value) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return output |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * `validateArguments` validates the arguments given to each function call. |
no outgoing calls
no test coverage detected
searching dependent graphs…