もったいないから、残しとく。
var decodeUtf8Array = function(ary) {
var s = "";
var uc = function(ind) {return (ary[ind] >= 0)? ary[ind]: (ary[ind] + 0xff + 1)};
for (i = 0; i < ary.length;) {
var c1 = uc(i);
if (c1 >= 0xf0) {
var c2 = uc(i+1);
var c3 = uc(i+2);
var c4 = uc(i+3);
s += String.fromCharCode(((c1 & 0x07) << 18) | ((c2 & 0x3f) << 12) | (c3 & 0x3f) << 6 | (c4 & 0x3f));
i += 4;
} else if (c1 >= 0xe0) {
var c2 = uc(i+1);
var c3 = uc(i+2);
s += String.fromCharCode(((c1 & 0x0f) << 12) | ((c2 & 0x3f) << 6) | (c3 & 0x3f));
i += 3;
} else if (c1 >= 0xc0) {
var c2 = uc(i+1);
s += String.fromCharCode(((c1 & 0x1f) << 6) | (c2 & 0x3f));
i += 2;
} else {
s += String.fromCharCode(c1 & 0x7f);
++i;
}
}
return s;
};
0 件のコメント:
コメントを投稿