mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-26 09:24:07 +00:00
refactor(zip) decode
This commit is contained in:
parent
be193bad85
commit
bce8b9e206
1 changed files with 37 additions and 35 deletions
|
|
@ -56,42 +56,44 @@ var Util, Zip, pako;
|
|||
*/
|
||||
|
||||
function decode(s) {
|
||||
/*jshint bitwise:false */
|
||||
s = s.replace(/%([EF][0-9A-F])%([89AB][0-9A-F])%([89AB][0-9A-F])/gi,
|
||||
function(code,hex1,hex2,hex3) {
|
||||
var n, n3,
|
||||
n1 = parseInt(hex1,16) - 0xE0,
|
||||
n2 = parseInt(hex2,16) - 0x80;
|
||||
|
||||
if (n1 === 0 && n2 < 32)
|
||||
return code;
|
||||
|
||||
n3 = parseInt(hex3,16)-0x80;
|
||||
n = (n1<<12) + (n2<<6) + n3;
|
||||
|
||||
if (n > 0xFFFF)
|
||||
return code;
|
||||
|
||||
return String.fromCharCode(n);
|
||||
});
|
||||
s = s.replace(/%([CD][0-9A-F])%([89AB][0-9A-F])/gi,
|
||||
function(code,hex1,hex2) {
|
||||
var n1, n2;
|
||||
|
||||
n1 = parseInt(hex1,16) - 0xC0;
|
||||
|
||||
if (n1 < 2)
|
||||
return code;
|
||||
|
||||
n2 = parseInt(hex2,16) - 0x80;
|
||||
|
||||
return String.fromCharCode((n1<<6) + n2);
|
||||
});
|
||||
s = s.replace(/%([0-7][0-9A-F])/gi,
|
||||
function(code, hex) {
|
||||
return String.fromCharCode(parseInt(hex,16));
|
||||
});
|
||||
s = s.replace(/%([EF][0-9A-F])%([89AB][0-9A-F])%([89AB][0-9A-F])/gi, ef)
|
||||
.replace(/%([CD][0-9A-F])%([89AB][0-9A-F])/gi, cd)
|
||||
.replace(/%([0-7][0-9A-F])/gi, o7);
|
||||
|
||||
return s;
|
||||
|
||||
function o7(code, hex) {
|
||||
return String.fromCharCode(parseInt(hex,16));
|
||||
}
|
||||
|
||||
function ef(code, hex1, hex2, hex3) {
|
||||
var n, n3,
|
||||
n1 = parseInt(hex1,16) - 0xE0,
|
||||
n2 = parseInt(hex2,16) - 0x80;
|
||||
|
||||
if (n1 === 0 && n2 < 32)
|
||||
return code;
|
||||
|
||||
n3 = parseInt(hex3,16)-0x80;
|
||||
n = (n1<<12) + (n2<<6) + n3;
|
||||
|
||||
if (n > 0xFFFF)
|
||||
return code;
|
||||
|
||||
return String.fromCharCode(n);
|
||||
}
|
||||
|
||||
function cd(code, hex1, hex2) {
|
||||
var n1, n2;
|
||||
|
||||
n1 = parseInt(hex1,16) - 0xC0;
|
||||
|
||||
if (n1 < 2)
|
||||
return code;
|
||||
|
||||
n2 = parseInt(hex2,16) - 0x80;
|
||||
|
||||
return String.fromCharCode((n1<<6) + n2);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue