2016-01-16 03:27:02 +00:00
|
|
|
/+ACo cputils.js (C) 2013-present SheetJS -- http://sheetjs.com +ACo-/
|
2016-09-22 17:42:47 +00:00
|
|
|
/+ACo vim: set ft+AD0-javascript: +ACo-/
|
2014-04-14 20:45:36 +00:00
|
|
|
/+ACo-jshint newcap: false +ACo-/
|
2016-09-22 17:42:47 +00:00
|
|
|
(function(root, factory) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
+ACI-use strict+ACIAOw
|
|
|
|
if(typeof cptable +AD0APQA9 +ACI-undefined+ACI) +AHs
|
|
|
|
if(typeof require +ACEAPQA9 +ACI-undefined+ACI)+AHs
|
2017-03-10 21:26:53 +00:00
|
|
|
var cpt +AD0 require('./cptable')+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if (typeof module +ACEAPQA9 'undefined' +ACYAJg module.exports) module.exports +AD0 factory(cpt)+ADs
|
|
|
|
else root.cptable +AD0 factory(cpt)+ADs
|
|
|
|
+AH0 else throw new Error(+ACI-cptable not found+ACI)+ADs
|
|
|
|
+AH0 else cptable +AD0 factory(cptable)+ADs
|
|
|
|
+AH0(this, function(cpt)+AHs
|
|
|
|
+ACI-use strict+ACIAOw
|
|
|
|
var magic +AD0 +AHs
|
|
|
|
+ACI-1200+ACI:+ACI-utf16le+ACI,
|
|
|
|
+ACI-1201+ACI:+ACI-utf16be+ACI,
|
|
|
|
+ACI-12000+ACI:+ACI-utf32le+ACI,
|
|
|
|
+ACI-12001+ACI:+ACI-utf32be+ACI,
|
|
|
|
+ACI-16969+ACI:+ACI-utf64le+ACI,
|
|
|
|
+ACI-20127+ACI:+ACI-ascii+ACI,
|
|
|
|
+ACI-65000+ACI:+ACI-utf7+ACI,
|
|
|
|
+ACI-65001+ACI:+ACI-utf8+ACI
|
|
|
|
+AH0AOw
|
|
|
|
|
|
|
|
var sbcs+AF8-cache +AD0 +AFs-874,1250,1251,1252,1253,1254,1255,1256,10000+AF0AOw
|
|
|
|
var dbcs+AF8-cache +AD0 +AFs-932,936,949,950+AF0AOw
|
|
|
|
var magic+AF8-cache +AD0 +AFs-65001+AF0AOw
|
|
|
|
var magic+AF8-decode +AD0 +AHsAfQA7
|
|
|
|
var magic+AF8-encode +AD0 +AHsAfQA7
|
2014-06-26 05:54:13 +00:00
|
|
|
var cpdcache +AD0 +AHsAfQA7
|
2016-09-22 17:42:47 +00:00
|
|
|
var cpecache +AD0 +AHsAfQA7
|
2014-04-14 20:45:36 +00:00
|
|
|
|
2014-12-25 20:50:25 +00:00
|
|
|
var sfcc +AD0 function sfcc(x) +AHs return String.fromCharCode(x)+ADs +AH0AOw
|
2016-09-22 17:42:47 +00:00
|
|
|
var cca +AD0 function cca(x) +AHs return x.charCodeAt(0)+ADs +AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
|
|
|
|
var has+AF8-buf +AD0 (typeof Buffer +ACEAPQA9 'undefined')+ADs
|
|
|
|
if(has+AF8-buf) +AHs
|
|
|
|
var mdl +AD0 1024, mdb +AD0 new Buffer(mdl)+ADs
|
|
|
|
var make+AF8-EE +AD0 function make+AF8-EE(E)+AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
var EE +AD0 new Buffer(65536)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(var i +AD0 0+ADs i +ADw 65536+ADsAKwAr-i) EE+AFs-i+AF0 +AD0 0+ADs
|
2014-06-26 05:54:13 +00:00
|
|
|
var keys +AD0 Object.keys(E), len +AD0 keys.length+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(var ee +AD0 0, e +AD0 keys+AFs-ee+AF0AOw ee +ADw len+ADs +-+-ee) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(+ACE(e +AD0 keys+AFs-ee+AF0)) continue+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
EE+AFs-e.charCodeAt(0)+AF0 +AD0 E+AFs-e+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
+AH0
|
|
|
|
return EE+ADs
|
|
|
|
+AH0AOw
|
|
|
|
var sbcs+AF8-encode +AD0 function make+AF8-sbcs+AF8-encode(cp) +AHs
|
|
|
|
var EE +AD0 make+AF8-EE(cpt+AFs-cp+AF0.enc)+ADs
|
|
|
|
return function sbcs+AF8-e(data, ofmt) +AHs
|
|
|
|
var len +AD0 data.length+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
var out, i+AD0-0, j+AD0-0, D+AD0-0, w+AD0-0+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(typeof data +AD0APQA9 'string') +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
out +AD0 new Buffer(len)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) out+AFs-i+AF0 +AD0 EE+AFs-data.charCodeAt(i)+AF0AOw
|
|
|
|
+AH0 else if(Buffer.isBuffer(data)) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
out +AD0 new Buffer(2+ACo-len)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
j +AD0 0+ADs
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
|
|
|
D +AD0 data+AFs-i+AF0AOw
|
|
|
|
if(D +ADw 128) out+AFs-j+-+-+AF0 +AD0 EE+AFs-D+AF0AOw
|
|
|
|
else if(D +ADw 224) +AHs out+AFs-j+-+-+AF0 +AD0 EE+AFs((D+ACY-31)+ADwAPA-6)+-(data+AFs-i+-1+AF0AJg-63)+AF0AOw +-+-i+ADs +AH0
|
|
|
|
else if(D +ADw 240) +AHs out+AFs-j+-+-+AF0 +AD0 EE+AFs((D+ACY-15)+ADwAPA-12)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-2+AF0AJg-63)+AF0AOw i+-+AD0-2+ADs +AH0
|
|
|
|
else +AHs
|
|
|
|
w +AD0 ((D+ACY-7)+ADwAPA-18)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-((data+AFs-i+-2+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-3+AF0AJg-63)+ADs i+-+AD0-3+ADs
|
|
|
|
if(w +ADw 65536) out+AFs-j+-+-+AF0 +AD0 EE+AFs-w+AF0AOw
|
|
|
|
else +AHs w -+AD0 65536+ADs out+AFs-j+-+-+AF0 +AD0 EE+AFs-0xD800 +- ((w+AD4APg-10)+ACY-1023)+AF0AOw out+AFs-j+-+-+AF0 +AD0 EE+AFs-0xDC00 +- (w+ACY-1023)+AF0AOw +AH0
|
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
out +AD0 out.slice(0,j)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0 else +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
out +AD0 new Buffer(len)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) out+AFs-i+AF0 +AD0 EE+AFs-data+AFs-i+AF0.charCodeAt(0)+AF0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
|
|
|
|
return +AFsAXQ.slice.call(out)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
+AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
var sbcs+AF8-decode +AD0 function make+AF8-sbcs+AF8-decode(cp) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
var D +AD0 cpt+AFs-cp+AF0.dec+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
var DD +AD0 new Buffer(131072), d+AD0-0, c+AD0AIgAiADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(d+AD0-0+ADs-d+ADw-D.length+ADsAKwAr-d) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(+ACE(c+AD0-D+AFs-d+AF0)) continue+ADs
|
|
|
|
var w +AD0 c.charCodeAt(0)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
DD+AFs-2+ACo-d+AF0 +AD0 w+ACY-255+ADs DD+AFs-2+ACo-d+-1+AF0 +AD0 w+AD4APg-8+ADs
|
2014-06-26 05:54:13 +00:00
|
|
|
+AH0
|
2014-12-25 20:50:25 +00:00
|
|
|
return function sbcs+AF8-d(data) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
var len +AD0 data.length, i+AD0-0, j+AD0-0+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(2 +ACo len +AD4 mdl) +AHs mdl +AD0 2 +ACo len+ADs mdb +AD0 new Buffer(mdl)+ADs +AH0
|
|
|
|
if(Buffer.isBuffer(data)) +AHs
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data+AFs-i+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0 else if(typeof data +AD0APQA9 +ACI-string+ACI) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data.charCodeAt(i)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0 else +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data+AFs-i+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0
|
2016-01-16 03:27:02 +00:00
|
|
|
return mdb.slice(0, 2 +ACo len).toString('ucs2')+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
+AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
var dbcs+AF8-encode +AD0 function make+AF8-dbcs+AF8-encode(cp) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
var E +AD0 cpt+AFs-cp+AF0.enc+ADs
|
2014-06-26 05:54:13 +00:00
|
|
|
var EE +AD0 new Buffer(131072)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(var i +AD0 0+ADs i +ADw 131072+ADs +-+-i) EE+AFs-i+AF0 +AD0 0+ADs
|
2014-06-26 05:54:13 +00:00
|
|
|
var keys +AD0 Object.keys(E)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(var ee +AD0 0, e +AD0 keys+AFs-ee+AF0AOw ee +ADw keys.length+ADs +-+-ee) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(+ACE(e +AD0 keys+AFs-ee+AF0)) continue+ADs
|
|
|
|
var f +AD0 e.charCodeAt(0)+ADs
|
|
|
|
EE+AFs-2+ACo-f+AF0 +AD0 E+AFs-e+AF0 +ACY 255+ADs EE+AFs-2+ACo-f+-1+AF0 +AD0 E+AFs-e+AF0APgA+-8+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
+AH0
|
|
|
|
return function dbcs+AF8-e(data, ofmt) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
var len +AD0 data.length, out +AD0 new Buffer(2+ACo-len), i+AD0-0, j+AD0-0, jj+AD0-0, k+AD0-0, D+AD0-0+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(typeof data +AD0APQA9 'string') +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 data.charCodeAt(i)+ACo-2+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
|
|
|
|
+AH0
|
2014-12-25 20:50:25 +00:00
|
|
|
out +AD0 out.slice(0,k)+ADs
|
|
|
|
+AH0 else if(Buffer.isBuffer(data)) +AHs
|
|
|
|
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
|
|
|
D +AD0 data+AFs-i+AF0AOw
|
|
|
|
if(D +ADw 128) j +AD0 D+ADs
|
|
|
|
else if(D +ADw 224) +AHs j +AD0 ((D+ACY-31)+ADwAPA-6)+-(data+AFs-i+-1+AF0AJg-63)+ADs +-+-i+ADs +AH0
|
|
|
|
else if(D +ADw 240) +AHs j +AD0 ((D+ACY-15)+ADwAPA-12)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-2+AF0AJg-63)+ADs i+-+AD0-2+ADs +AH0
|
|
|
|
else +AHs j +AD0 ((D+ACY-7)+ADwAPA-18)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-((data+AFs-i+-2+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-3+AF0AJg-63)+ADs i+-+AD0-3+ADs +AH0
|
|
|
|
if(j+ADw-65536) +AHs j+ACoAPQ-2+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw +AH0
|
|
|
|
else +AHs jj +AD0 j-65536+ADs
|
|
|
|
j+AD0-2+ACo(0xD800 +- ((jj+AD4APg-10)+ACY-1023))+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
|
|
|
|
j+AD0-2+ACo(0xDC00 +- (jj+ACY-1023))+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
|
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
out +AD0 out.slice(0,k)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0 else +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 data+AFs-i+AF0.charCodeAt(0)+ACo-2+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
|
|
|
|
+AH0
|
|
|
|
+AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
|
|
|
|
return +AFsAXQ.slice.call(out)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
+AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
var dbcs+AF8-decode +AD0 function make+AF8-dbcs+AF8-decode(cp) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
var D +AD0 cpt+AFs-cp+AF0.dec+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
var DD +AD0 new Buffer(131072), d+AD0-0, c, w+AD0-0, j+AD0-0, i+AD0-0+ADs
|
|
|
|
for(i +AD0 0+ADs i +ADw 65536+ADs +-+-i) +AHs DD+AFs-2+ACo-i+AF0 +AD0 0xFF+ADs DD+AFs-2+ACo-i+-1+AF0 +AD0 0xFD+ADsAfQ
|
|
|
|
for(d +AD0 0+ADs d +ADw D.length+ADs +-+-d) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(+ACE(c+AD0-D+AFs-d+AF0)) continue+ADs
|
|
|
|
w +AD0 c.charCodeAt(0)+ADs
|
|
|
|
j +AD0 2+ACo-d+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
DD+AFs-j+AF0 +AD0 w+ACY-255+ADs DD+AFs-j+-1+AF0 +AD0 w+AD4APg-8+ADs
|
|
|
|
+AH0
|
|
|
|
return function dbcs+AF8-d(data) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
var len +AD0 data.length, out +AD0 new Buffer(2+ACo-len), i+AD0-0, j+AD0-0, k+AD0-0+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(Buffer.isBuffer(data)) +AHs
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data+AFs-i+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data+AFs-i+AF0APAA8-8)+-data+AFs-i+-1+AF0)+ADs +-+-i+ADs +AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
|
|
|
+AH0
|
|
|
|
+AH0 else if(typeof data +AD0APQA9 +ACI-string+ACI) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data.charCodeAt(i)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data.charCodeAt(i)+ADwAPA-8)+-data.charCodeAt(i+-1))+ADs +-+-i+ADs +AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
|
|
|
+AH0
|
|
|
|
+AH0 else +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ACo-data+AFs-i+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data+AFs-i+AF0APAA8-8)+-data+AFs-i+-1+AF0)+ADs +-+-i+ADs +AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
|
|
|
|
+AH0
|
|
|
|
+AH0
|
2016-01-16 03:27:02 +00:00
|
|
|
return out.slice(0,k).toString('ucs2')+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
+AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
magic+AF8-decode+AFs-65001+AF0 +AD0 function utf8+AF8-d(data) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
if(typeof data +AD0APQA9 +ACI-string+ACI) return utf8+AF8-d(data.split(+ACIAIg).map(cca))+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
var len +AD0 data.length, w +AD0 0, ww +AD0 0+ADs
|
|
|
|
if(4 +ACo len +AD4 mdl) +AHs mdl +AD0 4 +ACo len+ADs mdb +AD0 new Buffer(mdl)+ADs +AH0
|
|
|
|
var i +AD0 0+ADs
|
|
|
|
if(len +AD4APQ 3 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xEF) if(data+AFs-1+AF0 +AD0APQ 0xBB +ACYAJg data+AFs-2+AF0 +AD0APQ 0xBF) i +AD0 3+ADs
|
|
|
|
for(var j +AD0 1, k +AD0 0, D +AD0 0+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
|
|
|
j +AD0 1+ADs D +AD0 data+AFs-i+AF0AOw
|
|
|
|
if(D +ADw 128) w +AD0 D+ADs
|
|
|
|
else if(D +ADw 224) +AHs w+AD0(D+ACY-31)+ACo-64+-(data+AFs-i+-1+AF0AJg-63)+ADs j+AD0-2+ADs +AH0
|
|
|
|
else if(D +ADw 240) +AHs w+AD0((D+ACY-15)+ADwAPA-12)+-(data+AFs-i+-1+AF0AJg-63)+ACo-64+-(data+AFs-i+-2+AF0AJg-63)+ADs j+AD0-3+ADs +AH0
|
|
|
|
else +AHs w+AD0(D+ACY-7)+ACo-262144+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-(data+AFs-i+-2+AF0AJg-63)+ACo-64+-(data+AFs-i+-3+AF0AJg-63)+ADs j+AD0-4+ADs +AH0
|
|
|
|
if(w +ADw 65536) +AHs mdb+AFs-k+-+-+AF0 +AD0 w+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 w+AD4APg-8+ADs +AH0
|
2014-06-26 05:54:13 +00:00
|
|
|
else +AHs
|
|
|
|
w -+AD0 65536+ADs ww +AD0 0xD800 +- ((w+AD4APg-10)+ACY-1023)+ADs w +AD0 0xDC00 +- (w+ACY-1023)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
mdb+AFs-k+-+-+AF0 +AD0 ww+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 ww+AD4APgA+-8+ADs mdb+AFs-k+-+-+AF0 +AD0 w+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 (w+AD4APgA+-8)+ACY-255+ADs
|
2014-06-26 05:54:13 +00:00
|
|
|
+AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
2016-01-16 03:27:02 +00:00
|
|
|
return mdb.slice(0,k).toString('ucs2')+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
+AH0AOw
|
|
|
|
magic+AF8-encode+AFs-65001+AF0 +AD0 function utf8+AF8-e(data, ofmt) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) +AHs
|
|
|
|
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return data+ADs
|
|
|
|
if(ofmt +ACEAPQA9 'arr') return data.toString('binary')+ADs
|
|
|
|
return +AFsAXQ.slice.call(data)+ADs
|
|
|
|
+AH0
|
2014-12-25 20:50:25 +00:00
|
|
|
var len +AD0 data.length, w +AD0 0, ww +AD0 0, j +AD0 0+ADs
|
|
|
|
var direct +AD0 typeof data +AD0APQA9 +ACI-string+ACIAOw
|
|
|
|
if(4 +ACo len +AD4 mdl) +AHs mdl +AD0 4 +ACo len+ADs mdb +AD0 new Buffer(mdl)+ADs +AH0
|
|
|
|
for(var i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
|
|
|
w +AD0 direct ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
|
|
|
if(w +ADwAPQ 0x007F) mdb+AFs-j+-+-+AF0 +AD0 w+ADs
|
|
|
|
else if(w +ADwAPQ 0x07FF) +AHs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 192 +- (w +AD4APg 6)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 128 +- (w+ACY-63)+ADs
|
|
|
|
+AH0 else if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) +AHs
|
|
|
|
w -+AD0 0xD800+ADs +-+-i+ADs
|
|
|
|
ww +AD0 (direct ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)) - 0xDC00 +- (w +ADwAPA 10)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 240 +- ((ww+AD4APgA+-18) +ACY 0x07)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 144 +- ((ww+AD4APgA+-12) +ACY 0x3F)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 128 +- ((ww+AD4APgA+-6) +ACY 0x3F)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 128 +- (ww +ACY 0x3F)+ADs
|
|
|
|
+AH0 else +AHs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 224 +- (w +AD4APg 12)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 128 +- ((w +AD4APg 6)+ACY-63)+ADs
|
|
|
|
mdb+AFs-j+-+-+AF0 +AD0 128 +- (w+ACY-63)+ADs
|
|
|
|
+AH0
|
|
|
|
+AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return mdb.slice(0,j)+ADs
|
2016-01-16 03:27:02 +00:00
|
|
|
if(ofmt +ACEAPQA9 'arr') return mdb.slice(0,j).toString('binary')+ADs
|
|
|
|
return +AFsAXQ.slice.call(mdb, 0, j)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
+AH0
|
|
|
|
|
2014-12-25 20:50:25 +00:00
|
|
|
var encache +AD0 function encache() +AHs
|
|
|
|
if(has+AF8-buf) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(cpdcache+AFs-sbcs+AF8-cache+AFs-0+AF0AXQ) return+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
var i+AD0-0, s+AD0-0+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw sbcs+AF8-cache.length+ADs +-+-i) +AHs
|
|
|
|
s +AD0 sbcs+AF8-cache+AFs-i+AF0AOw
|
|
|
|
if(cpt+AFs-s+AF0) +AHs
|
|
|
|
cpdcache+AFs-s+AF0 +AD0 sbcs+AF8-decode(s)+ADs
|
|
|
|
cpecache+AFs-s+AF0 +AD0 sbcs+AF8-encode(s)+ADs
|
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
for(i +AD0 0+ADs i +ADw dbcs+AF8-cache.length+ADs +-+-i) +AHs
|
|
|
|
s +AD0 dbcs+AF8-cache+AFs-i+AF0AOw
|
|
|
|
if(cpt+AFs-s+AF0) +AHs
|
|
|
|
cpdcache+AFs-s+AF0 +AD0 dbcs+AF8-decode(s)+ADs
|
|
|
|
cpecache+AFs-s+AF0 +AD0 dbcs+AF8-encode(s)+ADs
|
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
for(i +AD0 0+ADs i +ADw magic+AF8-cache.length+ADs +-+-i) +AHs
|
|
|
|
s +AD0 magic+AF8-cache+AFs-i+AF0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
if(magic+AF8-decode+AFs-s+AF0) cpdcache+AFs-s+AF0 +AD0 magic+AF8-decode+AFs-s+AF0AOw
|
|
|
|
if(magic+AF8-encode+AFs-s+AF0) cpecache+AFs-s+AF0 +AD0 magic+AF8-encode+AFs-s+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
+AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0AOw
|
2016-09-22 17:42:47 +00:00
|
|
|
var null+AF8-enc +AD0 function(data, ofmt) +AHs return +ACIAIgA7 +AH0AOw
|
|
|
|
var cp+AF8-decache +AD0 function cp+AF8-decache(cp) +AHs delete cpdcache+AFs-cp+AF0AOw delete cpecache+AFs-cp+AF0AOw +AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
var decache +AD0 function decache() +AHs
|
|
|
|
if(has+AF8-buf) +AHs
|
2014-06-26 05:54:13 +00:00
|
|
|
if(+ACE-cpdcache+AFs-sbcs+AF8-cache+AFs-0+AF0AXQ) return+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
sbcs+AF8-cache.forEach(cp+AF8-decache)+ADs
|
|
|
|
dbcs+AF8-cache.forEach(cp+AF8-decache)+ADs
|
|
|
|
magic+AF8-cache.forEach(cp+AF8-decache)+ADs
|
|
|
|
+AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
last+AF8-enc +AD0 null+AF8-enc+ADs last+AF8-cp +AD0 0+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
|
|
|
var cache +AD0 +AHs
|
|
|
|
encache: encache,
|
|
|
|
decache: decache,
|
|
|
|
sbcs: sbcs+AF8-cache,
|
|
|
|
dbcs: dbcs+AF8-cache
|
|
|
|
+AH0AOw
|
|
|
|
|
|
|
|
encache()+ADs
|
|
|
|
|
|
|
|
var BM +AD0 +ACI-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-/+ACIAOw
|
|
|
|
var SetD +AD0 +ACI-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?+ACIAOw
|
2016-09-22 17:42:47 +00:00
|
|
|
var last+AF8-enc +AD0 null+AF8-enc, last+AF8-cp +AD0 0+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
var encode +AD0 function encode(cp, data, ofmt) +AHs
|
2016-09-22 17:42:47 +00:00
|
|
|
if(cp +AD0APQA9 last+AF8-cp +ACYAJg last+AF8-enc) +AHs return last+AF8-enc(data, ofmt)+ADs +AH0
|
|
|
|
if(cpecache+AFs-cp+AF0) +AHs last+AF8-enc +AD0 cpecache+AFs-last+AF8-cp+AD0-cp+AF0AOw return last+AF8-enc(data, ofmt)+ADs +AH0
|
2014-12-25 20:50:25 +00:00
|
|
|
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) data +AD0 data.toString('utf8')+ADs
|
|
|
|
var len +AD0 data.length+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
var out +AD0 has+AF8-buf ? new Buffer(4+ACo-len) : +AFsAXQ, w+AD0-0, i+AD0-0, j +AD0 0, ww+AD0-0+ADs
|
|
|
|
var C +AD0 cpt+AFs-cp+AF0, E, M +AD0 +ACIAIgA7
|
2016-10-15 06:09:05 +00:00
|
|
|
var isstr +AD0 typeof data +AD0APQA9 'string'+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(C +ACYAJg (E+AD0-C.enc)) for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 E+AFs-isstr? data.charAt(i) : data+AFs-i+AF0AXQA7
|
2014-04-14 20:45:36 +00:00
|
|
|
if(w +AD4 255) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-j+AF0 +AD0 w+AD4APg-8+ADs
|
|
|
|
out+AFsAKwAr-j+AF0 +AD0 w+ACY-255+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
+AH0 else out+AFs-j+AF0 +AD0 w+ACY-255+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
else if((M+AD0-magic+AFs-cp+AF0)) switch(M) +AHs
|
|
|
|
case +ACI-utf8+ACI:
|
2016-10-15 06:09:05 +00:00
|
|
|
if(has+AF8-buf +ACYAJg isstr) +AHs out +AD0 new Buffer(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(w +ADwAPQ 0x007F) out+AFs-j+AF0 +AD0 w+ADs
|
|
|
|
else if(w +ADwAPQ 0x07FF) +AHs
|
|
|
|
out+AFs-j+AF0 +AD0 192 +- (w +AD4APg 6)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFsAKwAr-j+AF0 +AD0 128 +- (w+ACY-63)+ADs
|
|
|
|
+AH0 else if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) +AHs
|
|
|
|
w -+AD0 0xD800+ADs
|
2016-10-15 06:09:05 +00:00
|
|
|
ww +AD0 (isstr ? data.charCodeAt(+-+-i) : data+AFsAKwAr-i+AF0.charCodeAt(0)) - 0xDC00 +- (w +ADwAPA 10)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-j+AF0 +AD0 240 +- ((ww+AD4APgA+-18) +ACY 0x07)+ADs
|
|
|
|
out+AFsAKwAr-j+AF0 +AD0 144 +- ((ww+AD4APgA+-12) +ACY 0x3F)+ADs
|
|
|
|
out+AFsAKwAr-j+AF0 +AD0 128 +- ((ww+AD4APgA+-6) +ACY 0x3F)+ADs
|
|
|
|
out+AFsAKwAr-j+AF0 +AD0 128 +- (ww +ACY 0x3F)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0 else +AHs
|
|
|
|
out+AFs-j+AF0 +AD0 224 +- (w +AD4APg 12)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFsAKwAr-j+AF0 +AD0 128 +- ((w +AD4APg 6)+ACY-63)+ADs
|
|
|
|
out+AFsAKwAr-j+AF0 +AD0 128 +- (w+ACY-63)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-ascii+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(has+AF8-buf +ACYAJg typeof data +AD0APQA9 +ACI-string+ACI) +AHs out +AD0 new Buffer(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(w +ADwAPQ 0x007F) out+AFs-j+AF0 +AD0 w+ADs
|
|
|
|
else throw new Error(+ACI-bad ascii +ACI +- w)+ADs
|
|
|
|
+AH0
|
|
|
|
break+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
case +ACI-utf16le+ACI:
|
|
|
|
if(has+AF8-buf +ACYAJg typeof data +AD0APQA9 +ACI-string+ACI) +AHs out +AD0 new Buffer(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+AD4APg-8+ADs
|
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf16be+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+AD4APg-8+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf32le+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) w +AD0 0x10000 +- ((w - 0xD800) +ADwAPA 10) +- (data+AFsAKwAr-i+AF0.charCodeAt(0) - 0xDC00)+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf32be+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) w +AD0 0x10000 +- ((w - 0xD800) +ADwAPA 10) +- (data+AFsAKwAr-i+AF0.charCodeAt(0) - 0xDC00)+ADs
|
|
|
|
out+AFs-j+-3+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
|
|
|
out+AFs-j+-2+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
|
|
|
out+AFs-j+-1+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
out+AFs-j+AF0 +AD0 w+ACY-255+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
j+-+AD0-4+ADs
|
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf7+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
|
2016-10-15 06:09:05 +00:00
|
|
|
var c +AD0 isstr ? data.charAt(i) : data+AFs-i+AF0.charAt(0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(c +AD0APQA9 +ACIAKwAi) +AHs out+AFs-j+-+-+AF0 +AD0 0x2b+ADs out+AFs-j+-+-+AF0 +AD0 0x2d+ADs continue+ADs +AH0
|
|
|
|
if(SetD.indexOf(c) +AD4 -1) +AHs out+AFs-j+-+-+AF0 +AD0 c.charCodeAt(0)+ADs continue+ADs +AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
var tt +AD0 encode(1201, c)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
out+AFs-j+-+-+AF0 +AD0 0x2b+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(tt+AFs-0+AF0APgA+-2)+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(((tt+AFs-0+AF0AJg-0x03)+ADwAPA-4) +- ((tt+AFs-1+AF0AfAB8-0)+AD4APg-4))+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(((tt+AFs-1+AF0AJg-0x0F)+ADwAPA-2) +- ((tt+AFs-2+AF0AfAB8-0)+AD4APg-6))+ADs
|
|
|
|
out+AFs-j+-+-+AF0 +AD0 0x2d+ADs
|
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
default: throw new Error(+ACI-Unsupported magic: +ACI +- cp +- +ACI +ACI +- magic+AFs-cp+AF0)+ADs
|
|
|
|
+AH0
|
|
|
|
else throw new Error(+ACI-Unrecognized CP: +ACI +- cp)+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
out +AD0 out.slice(0,j)+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
if(+ACE-has+AF8-buf) return (ofmt +AD0APQ 'str') ? (out).map(sfcc).join(+ACIAIg) : out+ADs
|
|
|
|
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
|
|
|
|
return +AFsAXQ.slice.call(out)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
var decode +AD0 function decode(cp, data) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
var F+ADs if((F+AD0-cpdcache+AFs-cp+AF0)) return F(data)+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
if(typeof data +AD0APQA9 +ACI-string+ACI) return decode(cp, data.split(+ACIAIg).map(cca))+ADs
|
|
|
|
var len +AD0 data.length, out +AD0 new Array(len), s+AD0AIgAi, w+AD0-0, i+AD0-0, j+AD0-1, k+AD0-0, ww+AD0-0+ADs
|
|
|
|
var C +AD0 cpt+AFs-cp+AF0, D, M+AD0AIgAiADs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(C +ACYAJg (D+AD0-C.dec)) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
s +AD0 D+AFs(data+AFs-i+AF0APAA8-8)+- data+AFs-i+-1+AF0AXQA7
|
|
|
|
if(+ACE-s) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 1+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
s +AD0 D+AFs-data+AFs-i+AF0AXQA7
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
2016-09-22 17:42:47 +00:00
|
|
|
if(+ACE-s) throw new Error('Unrecognized code: ' +- data+AFs-i+AF0 +- ' ' +- data+AFs-i+-j-1+AF0 +- ' ' +- i +- ' ' +- j +- ' ' +- D+AFs-data+AFs-i+AF0AXQ)+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 s+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
+AH0
|
|
|
|
else if((M+AD0-magic+AFs-cp+AF0)) switch(M) +AHs
|
|
|
|
case +ACI-utf8+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(len +AD4APQ 3 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xEF) if(data+AFs-1+AF0 +AD0APQ 0xBB +ACYAJg data+AFs-2+AF0 +AD0APQ 0xBF) i +AD0 3+ADs
|
|
|
|
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 1+ADs
|
|
|
|
if(data+AFs-i+AF0 +ADw 128) w +AD0 data+AFs-i+AF0AOw
|
2014-12-25 20:50:25 +00:00
|
|
|
else if(data+AFs-i+AF0 +ADw 224) +AHs w+AD0(data+AFs-i+AF0AJg-31)+ACo-64+-(data+AFs-i+-1+AF0AJg-63)+ADs j+AD0-2+ADs +AH0
|
|
|
|
else if(data+AFs-i+AF0 +ADw 240) +AHs w+AD0((data+AFs-i+AF0AJg-15)+ADwAPA-12)+-(data+AFs-i+-1+AF0AJg-63)+ACo-64+-(data+AFs-i+-2+AF0AJg-63)+ADs j+AD0-3+ADs +AH0
|
|
|
|
else +AHs w+AD0(data+AFs-i+AF0AJg-7)+ACo-262144+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-(data+AFs-i+-2+AF0AJg-63)+ACo-64+-(data+AFs-i+-3+AF0AJg-63)+ADs j+AD0-4+ADs +AH0
|
|
|
|
if(w +ADw 65536) +AHs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs +AH0
|
|
|
|
else +AHs
|
|
|
|
w -+AD0 65536+ADs ww +AD0 0xD800 +- ((w+AD4APg-10)+ACY-1023)+ADs w +AD0 0xDC00 +- (w+ACY-1023)+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(ww)+ADs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
|
|
|
|
+AH0
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-ascii+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) return data.toString(M)+ADs
|
|
|
|
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) out+AFs-i+AF0 +AD0 String.fromCharCode(data+AFs-i+AF0)+ADs
|
|
|
|
k +AD0 len+ADs break+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
case +ACI-utf16le+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(len +AD4APQ 2 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFF) if(data+AFs-1+AF0 +AD0APQ 0xFE) i +AD0 2+ADs
|
|
|
|
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) return data.toString(M)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
for(+ADs i+-1 +ADw len+ADs i+-+AD0-j) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode((data+AFs-i+-1+AF0APAA8-8) +- data+AFs-i+AF0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf16be+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(len +AD4APQ 2 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFE) if(data+AFs-1+AF0 +AD0APQ 0xFF) i +AD0 2+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 2+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
for(+ADs i+-1 +ADw len+ADs i+-+AD0-j) +AHs
|
2014-12-25 20:50:25 +00:00
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode((data+AFs-i+AF0APAA8-8) +- data+AFs-i+-1+AF0)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf32le+ACI:
|
2016-01-16 03:27:02 +00:00
|
|
|
if(len +AD4APQ 4 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFF) if(data+AFs-1+AF0 +AD0APQ 0xFE +ACYAJg data+AFs-2+AF0 +AD0APQA9 0 +ACYAJg data+AFs-3+AF0 +AD0APQA9 0) i +AD0 4+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 4+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
|
|
|
w +AD0 (data+AFs-i+-3+AF0APAA8-24) +- (data+AFs-i+-2+AF0APAA8-16) +- (data+AFs-i+-1+AF0APAA8-8) +- (data+AFs-i+AF0)+ADs
|
|
|
|
if(w +AD4 0xFFFF) +AHs
|
|
|
|
w -+AD0 0x10000+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xD800 +- ((w +AD4APg 10) +ACY 0x3FF))+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xDC00 +- (w +ACY 0x3FF))+ADs
|
|
|
|
+AH0
|
|
|
|
else out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf32be+ACI:
|
2016-01-16 03:27:02 +00:00
|
|
|
if(len +AD4APQ 4 +ACYAJg data+AFs-3+AF0 +AD0APQ 0xFF) if(data+AFs-2+AF0 +AD0APQ 0xFE +ACYAJg data+AFs-1+AF0 +AD0APQA9 0 +ACYAJg data+AFs-0+AF0 +AD0APQA9 0) i +AD0 4+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
j +AD0 4+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
|
|
|
w +AD0 (data+AFs-i+AF0APAA8-24) +- (data+AFs-i+-1+AF0APAA8-16) +- (data+AFs-i+-2+AF0APAA8-8) +- (data+AFs-i+-3+AF0)+ADs
|
|
|
|
if(w +AD4 0xFFFF) +AHs
|
|
|
|
w -+AD0 0x10000+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xD800 +- ((w +AD4APg 10) +ACY 0x3FF))+ADs
|
|
|
|
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xDC00 +- (w +ACY 0x3FF))+ADs
|
|
|
|
+AH0
|
|
|
|
else out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
case +ACI-utf7+ACI:
|
2014-12-25 20:50:25 +00:00
|
|
|
if(len +AD4APQ 4 +ACYAJg data+AFs-0+AF0 +AD0APQ 0x2B +ACYAJg data+AFs-1+AF0 +AD0APQ 0x2F +ACYAJg data+AFs-2+AF0 +AD0APQ 0x76) +AHs
|
|
|
|
if(len +AD4APQ 5 +ACYAJg data+AFs-3+AF0 +AD0APQ 0x38 +ACYAJg data+AFs-4+AF0 +AD0APQ 0x2D) i +AD0 5+ADs
|
|
|
|
else if(data+AFs-3+AF0 +AD0APQ 0x38 +AHwAfA data+AFs-3+AF0 +AD0APQ 0x39 +AHwAfA data+AFs-3+AF0 +AD0APQ 0x2B +AHwAfA data+AFs-3+AF0 +AD0APQ 0x2F) i +AD0 4+ADs
|
|
|
|
+AH0
|
|
|
|
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
|
2014-04-14 20:45:36 +00:00
|
|
|
if(data+AFs-i+AF0 +ACEAPQA9 0x2b) +AHs j+AD0-1+ADs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(data+AFs-i+AF0)+ADs continue+ADs +AH0
|
|
|
|
j+AD0-1+ADs
|
|
|
|
if(data+AFs-i+-1+AF0 +AD0APQA9 0x2d) +AHs j +AD0 2+ADs out+AFs-k+-+-+AF0 +AD0 +ACIAKwAiADs continue+ADs +AH0
|
|
|
|
while(String.fromCharCode(data+AFs-i+-j+AF0).match(/+AFs-A-Za-z0-9+-+AFw-/+AF0-/)) j+-+-+ADs
|
|
|
|
var dash +AD0 0+ADs
|
|
|
|
if(data+AFs-i+-j+AF0 +AD0APQA9 0x2d) +AHs +-+-j+ADs dash+AD0-1+ADs +AH0
|
|
|
|
var tt +AD0 +AFsAXQA7
|
2016-09-22 17:42:47 +00:00
|
|
|
var o64 +AD0 +ACIAIgA7
|
|
|
|
var c1+AD0-0, c2+AD0-0, c3+AD0-0+ADs
|
|
|
|
var e1+AD0-0, e2+AD0-0, e3+AD0-0, e4+AD0-0+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
for(var l +AD0 1+ADs l +ADw j - dash+ADs) +AHs
|
|
|
|
e1 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
|
|
|
|
e2 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
|
|
|
|
c1 +AD0 e1 +ADwAPA 2 +AHw e2 +AD4APg 4+ADs
|
|
|
|
tt.push(c1)+ADs
|
|
|
|
e3 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
|
|
|
|
if(e3 +AD0APQA9 -1) break+ADs
|
|
|
|
c2 +AD0 (e2 +ACY 15) +ADwAPA 4 +AHw e3 +AD4APg 2+ADs
|
|
|
|
tt.push(c2)+ADs
|
|
|
|
e4 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
|
|
|
|
if(e4 +AD0APQA9 -1) break+ADs
|
|
|
|
c3 +AD0 (e3 +ACY 3) +ADwAPA 6 +AHw e4+ADs
|
2014-12-25 20:50:25 +00:00
|
|
|
if(e4 +ADw 64) tt.push(c3)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
o64 +AD0 decode(1201, tt)+ADs
|
2016-09-22 17:42:47 +00:00
|
|
|
for(l +AD0 0+ADs l +ADw o64.length+ADs +-+-l) out+AFs-k+-+-+AF0 +AD0 o64.charAt(l)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0
|
|
|
|
break+ADs
|
|
|
|
default: throw new Error(+ACI-Unsupported magic: +ACI +- cp +- +ACI +ACI +- magic+AFs-cp+AF0)+ADs
|
|
|
|
+AH0
|
|
|
|
else throw new Error(+ACI-Unrecognized CP: +ACI +- cp)+ADs
|
2016-01-16 03:27:02 +00:00
|
|
|
return out.slice(0,k).join(+ACIAIg)+ADs
|
2014-04-14 20:45:36 +00:00
|
|
|
+AH0AOw
|
2016-09-22 17:42:47 +00:00
|
|
|
var hascp +AD0 function hascp(cp) +AHs return +ACEAIQ(cpt+AFs-cp+AF0 +AHwAfA magic+AFs-cp+AF0)+ADs +AH0AOw
|
2014-04-14 20:45:36 +00:00
|
|
|
cpt.utils +AD0 +AHs decode: decode, encode: encode, hascp: hascp, magic: magic, cache:cache +AH0AOw
|
|
|
|
return cpt+ADs
|
|
|
|
+AH0))+ADs
|