使用场景
一个UCS2解码的函数,直接调用即可
/*
* @Author: Park
* @Date: 2021-08-18 23:34:37
* @contact: QQ:7323650
*/
importClass(java.lang.StringBuffer) //需提前导入类
function UCS2解码(str) {
var length = str.length;
var stringBuffer = new StringBuffer(length);
var i = 0;
while (i < length) {
var i2 = i + 1;
var charAt = str.charAt(i);
if (charAt == '\\') {
i = i2 + 1;
var charAt2 = str.charAt(i2);
if (charAt2 == 'u') {
i2 = 0;
var i3 = 0;
while (i2 < 4) {
var i4 = i + 1;
charAt = str.charAt(i);
switch (charAt) {
case 48 /*48*/:
case 49 /*49*/:
case 50 /*50*/:
case 51 /*51*/:
case 52 /*52*/:
case 53 /*53*/:
case 54 /*54*/:
case 55 /*55*/:
case 56 /*56*/:
case 57 /*57*/:
i3 = ((i3 << 4) + charAt) - 48;
break;
default:
switch (charAt) {
case 65 /*65*/:
case 66 /*66*/:
case 67 /*67*/:
case 68 /*68*/:
case 69 /*69*/:
case 70 /*70*/:
i3 = (((i3 << 4) + 10) + charAt) - 65;
break;
default:
switch (charAt) {
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
i3 = (((i3 << 4) + 10) + charAt) - 97;
break;
default:
throw new IllegalArgumentException("Malformed \\uxxxx encoding.");
}
}
}
i2++;
i = i4;
}
stringBuffer.append(i3);
} else {
if (charAt2 == 't') {
charAt2 = '\t';
} else if (charAt2 == 'r') {
charAt2 = '\r';
} else if (charAt2 == 'n') {
charAt2 = '\n';
} else if (charAt2 == 'f') {
charAt2 = '\f';
}
stringBuffer.append(charAt2);
}
} else {
stringBuffer.append(charAt);
i = i2;
}
}
return stringBuffer.toString();
}