| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
|
Sebastian Noack
2016/02/21 02:21:08
Nice.js already comes with punycode. So does adblo
kzar
2016/02/21 11:31:19
Done.
| |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | |
| 4 * | |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License version 3 as | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 // | |
| 19 // This file has been generated automatically, relevant repositories: | |
| 20 // * https://hg.adblockplus.org/jshydra/ | |
| 21 // | |
| 22 | |
| 23 ; | |
| 24 (function(root) | |
| 25 { | |
| 26 var freeExports = typeof exports == "object" && exports; | |
| 27 var freeModule = typeof module == "object" && module && module.exports == free Exports && module; | |
| 28 var freeGlobal = typeof global == "object" && global; | |
| 29 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) | |
| 30 { | |
| 31 root = freeGlobal; | |
| 32 } | |
| 33 var punycode, maxInt = 2147483647, | |
| 34 base = 36, | |
| 35 tMin = 1, | |
| 36 tMax = 26, | |
| 37 skew = 38, | |
| 38 damp = 700, | |
| 39 initialBias = 72, | |
| 40 initialN = 128, | |
| 41 delimiter = "-", | |
| 42 regexPunycode = /^xn--/, | |
| 43 regexNonASCII = /[^ -~]/, | |
| 44 regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, | |
| 45 errors = { | |
| 46 "overflow": "Overflow: input needs wider integers to process", | |
| 47 "not-basic": "Illegal input >= 0x80 (not a basic code point)", | |
| 48 "invalid-input": "Invalid input" | |
| 49 }, baseMinusTMin = base - tMin, | |
| 50 floor = Math.floor, | |
| 51 stringFromCharCode = String.fromCharCode, | |
| 52 key; | |
| 53 | |
| 54 function error(type) | |
| 55 { | |
| 56 throw RangeError(errors[type]); | |
| 57 } | |
| 58 | |
| 59 function map(array, fn) | |
| 60 { | |
| 61 var length = array.length; | |
| 62 while (length--) | |
| 63 { | |
| 64 array[length] = fn(array[length]); | |
| 65 } | |
| 66 return array; | |
| 67 } | |
| 68 | |
| 69 function mapDomain(string, fn) | |
| 70 { | |
| 71 return map(string.split(regexSeparators), fn).join("."); | |
| 72 } | |
| 73 | |
| 74 function ucs2decode(string) | |
| 75 { | |
| 76 var output = [], | |
| 77 counter = 0, | |
| 78 length = string.length, | |
| 79 value, extra; | |
| 80 while (counter < length) | |
| 81 { | |
| 82 value = string.charCodeAt(counter++); | |
| 83 if (value >= 55296 && value <= 56319 && counter < length) | |
| 84 { | |
| 85 extra = string.charCodeAt(counter++); | |
| 86 if ((extra & 64512) == 56320) | |
| 87 { | |
| 88 output.push(((value & 1023) << 10) + (extra & 1023) + 65536); | |
| 89 } | |
| 90 else | |
| 91 { | |
| 92 output.push(value); | |
| 93 counter--; | |
| 94 } | |
| 95 } | |
| 96 else | |
| 97 { | |
| 98 output.push(value); | |
| 99 } | |
| 100 } | |
| 101 return output; | |
| 102 } | |
| 103 | |
| 104 function ucs2encode(array) | |
| 105 { | |
| 106 return map(array, function(value) | |
| 107 { | |
| 108 var output = ""; | |
| 109 if (value > 65535) | |
| 110 { | |
| 111 value -= 65536; | |
| 112 output += stringFromCharCode(value >>> 10 & 1023 | 55296); | |
| 113 value = 56320 | value & 1023; | |
| 114 } | |
| 115 output += stringFromCharCode(value); | |
| 116 return output; | |
| 117 }).join(""); | |
| 118 } | |
| 119 | |
| 120 function basicToDigit(codePoint) | |
| 121 { | |
| 122 if (codePoint - 48 < 10) | |
| 123 { | |
| 124 return codePoint - 22; | |
| 125 } | |
| 126 if (codePoint - 65 < 26) | |
| 127 { | |
| 128 return codePoint - 65; | |
| 129 } | |
| 130 if (codePoint - 97 < 26) | |
| 131 { | |
| 132 return codePoint - 97; | |
| 133 } | |
| 134 return base; | |
| 135 } | |
| 136 | |
| 137 function digitToBasic(digit, flag) | |
| 138 { | |
| 139 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); | |
| 140 } | |
| 141 | |
| 142 function adapt(delta, numPoints, firstTime) | |
| 143 { | |
| 144 var k = 0; | |
| 145 delta = firstTime ? floor(delta / damp) : delta >> 1; | |
| 146 delta += floor(delta / numPoints); | |
| 147 for (; delta > baseMinusTMin * tMax >> 1; k += base) | |
| 148 { | |
| 149 delta = floor(delta / baseMinusTMin); | |
| 150 } | |
| 151 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); | |
| 152 } | |
| 153 | |
| 154 function decode(input) | |
| 155 { | |
| 156 var output = [], | |
| 157 inputLength = input.length, | |
| 158 out, i = 0, | |
| 159 n = initialN, | |
| 160 bias = initialBias, | |
| 161 basic, j, index, oldi, w, k, digit, t, length, baseMinusT; | |
| 162 basic = input.lastIndexOf(delimiter); | |
| 163 if (basic < 0) | |
| 164 { | |
| 165 basic = 0; | |
| 166 } | |
| 167 for (j = 0; j < basic; ++j) | |
| 168 { | |
| 169 if (input.charCodeAt(j) >= 128) | |
| 170 { | |
| 171 error("not-basic"); | |
| 172 } | |
| 173 output.push(input.charCodeAt(j)); | |
| 174 } | |
| 175 for (index = basic > 0 ? basic + 1 : 0; index < inputLength;) | |
| 176 { | |
| 177 for ((oldi = i, w = 1, k = base);; k += base) | |
| 178 { | |
| 179 if (index >= inputLength) | |
| 180 { | |
| 181 error("invalid-input"); | |
| 182 } | |
| 183 digit = basicToDigit(input.charCodeAt(index++)); | |
| 184 if (digit >= base || digit > floor((maxInt - i) / w)) | |
| 185 { | |
| 186 error("overflow"); | |
| 187 } | |
| 188 i += digit * w; | |
| 189 t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; | |
| 190 if (digit < t) | |
| 191 { | |
| 192 break; | |
| 193 } | |
| 194 baseMinusT = base - t; | |
| 195 if (w > floor(maxInt / baseMinusT)) | |
| 196 { | |
| 197 error("overflow"); | |
| 198 } | |
| 199 w *= baseMinusT; | |
| 200 } | |
| 201 out = output.length + 1; | |
| 202 bias = adapt(i - oldi, out, oldi == 0); | |
| 203 if (floor(i / out) > maxInt - n) | |
| 204 { | |
| 205 error("overflow"); | |
| 206 } | |
| 207 n += floor(i / out); | |
| 208 i %= out; | |
| 209 output.splice(i++, 0, n); | |
| 210 } | |
| 211 return ucs2encode(output); | |
| 212 } | |
| 213 | |
| 214 function encode(input) | |
| 215 { | |
| 216 var n, delta, handledCPCount, basicLength, bias, j, m, q, k, t, currentValue , output = [], | |
| 217 inputLength, handledCPCountPlusOne, baseMinusT, qMinusT; | |
| 218 input = ucs2decode(input); | |
| 219 inputLength = input.length; | |
| 220 n = initialN; | |
| 221 delta = 0; | |
| 222 bias = initialBias; | |
| 223 for (j = 0; j < inputLength; ++j) | |
| 224 { | |
| 225 currentValue = input[j]; | |
| 226 if (currentValue < 128) | |
| 227 { | |
| 228 output.push(stringFromCharCode(currentValue)); | |
| 229 } | |
| 230 } | |
| 231 handledCPCount = basicLength = output.length; | |
| 232 if (basicLength) | |
| 233 { | |
| 234 output.push(delimiter); | |
| 235 } | |
| 236 while (handledCPCount < inputLength) | |
| 237 { | |
| 238 for ((m = maxInt, j = 0); j < inputLength; ++j) | |
| 239 { | |
| 240 currentValue = input[j]; | |
| 241 if (currentValue >= n && currentValue < m) | |
| 242 { | |
| 243 m = currentValue; | |
| 244 } | |
| 245 } | |
| 246 handledCPCountPlusOne = handledCPCount + 1; | |
| 247 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) | |
| 248 { | |
| 249 error("overflow"); | |
| 250 } | |
| 251 delta += (m - n) * handledCPCountPlusOne; | |
| 252 n = m; | |
| 253 for (j = 0; j < inputLength; ++j) | |
| 254 { | |
| 255 currentValue = input[j]; | |
| 256 if (currentValue < n && ++delta > maxInt) | |
| 257 { | |
| 258 error("overflow"); | |
| 259 } | |
| 260 if (currentValue == n) | |
| 261 { | |
| 262 for ((q = delta, k = base);; k += base) | |
| 263 { | |
| 264 t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; | |
| 265 if (q < t) | |
| 266 { | |
| 267 break; | |
| 268 } | |
| 269 qMinusT = q - t; | |
| 270 baseMinusT = base - t; | |
| 271 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT , 0))); | |
| 272 q = floor(qMinusT / baseMinusT); | |
| 273 } | |
| 274 output.push(stringFromCharCode(digitToBasic(q, 0))); | |
| 275 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLeng th); | |
| 276 delta = 0; | |
| 277 ++handledCPCount; | |
| 278 } | |
| 279 }++delta; | |
| 280 ++n; | |
| 281 } | |
| 282 return output.join(""); | |
| 283 } | |
| 284 | |
| 285 function toUnicode(domain) | |
| 286 { | |
| 287 return mapDomain(domain, function(string) | |
| 288 { | |
| 289 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string; | |
| 290 }); | |
| 291 } | |
| 292 | |
| 293 function toASCII(domain) | |
| 294 { | |
| 295 return mapDomain(domain, function(string) | |
| 296 { | |
| 297 return regexNonASCII.test(string) ? "xn--" + encode(string) : string; | |
| 298 }); | |
| 299 } | |
| 300 punycode = { | |
| 301 "version": "1.2.3", | |
| 302 "ucs2": { | |
| 303 "decode": ucs2decode, | |
| 304 "encode": ucs2encode | |
| 305 }, | |
| 306 "decode": decode, | |
| 307 "encode": encode, | |
| 308 "toASCII": toASCII, | |
| 309 "toUnicode": toUnicode | |
| 310 }; | |
| 311 if (typeof define == "function" && typeof define.amd == "object" && define.amd ) | |
| 312 { | |
| 313 define(function() | |
| 314 { | |
| 315 return punycode; | |
| 316 }); | |
| 317 } | |
| 318 else if (freeExports && !freeExports.nodeType) | |
| 319 { | |
| 320 if (freeModule) | |
| 321 { | |
| 322 freeModule.exports = punycode; | |
| 323 } | |
| 324 else | |
| 325 { | |
| 326 for (key in punycode) | |
| 327 { | |
| 328 punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); | |
| 329 } | |
| 330 } | |
| 331 } | |
| 332 else | |
| 333 { | |
| 334 root.punycode = punycode; | |
| 335 } | |
| 336 })(this); | |
| 337 | |
| OLD | NEW |