@@ 3605-3632 (lines=28) @@ | ||
3602 | // String.fromCharCode.apply than Uint16Array. |
|
3603 | var utf16buf = new Array(len*2); |
|
3604 | ||
3605 | for (out=0, i=0; i<len;) { |
|
3606 | c = buf[i++]; |
|
3607 | // quick process ascii |
|
3608 | if (c < 0x80) { utf16buf[out++] = c; continue; } |
|
3609 | ||
3610 | c_len = _utf8len[c]; |
|
3611 | // skip 5 & 6 byte codes |
|
3612 | if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; } |
|
3613 | ||
3614 | // apply mask on first byte |
|
3615 | c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; |
|
3616 | // join the rest |
|
3617 | while (c_len > 1 && i < len) { |
|
3618 | c = (c << 6) | (buf[i++] & 0x3f); |
|
3619 | c_len--; |
|
3620 | } |
|
3621 | ||
3622 | // terminated by end of string? |
|
3623 | if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; } |
|
3624 | ||
3625 | if (c < 0x10000) { |
|
3626 | utf16buf[out++] = c; |
|
3627 | } else { |
|
3628 | c -= 0x10000; |
|
3629 | utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff); |
|
3630 | utf16buf[out++] = 0xdc00 | (c & 0x3ff); |
|
3631 | } |
|
3632 | } |
|
3633 | ||
3634 | return buf2binstring(utf16buf, out); |
|
3635 | }; |
|
@@ 1726-1753 (lines=28) @@ | ||
1723 | // String.fromCharCode.apply than Uint16Array. |
|
1724 | var utf16buf = new Array(len*2); |
|
1725 | ||
1726 | for (out=0, i=0; i<len;) { |
|
1727 | c = buf[i++]; |
|
1728 | // quick process ascii |
|
1729 | if (c < 0x80) { utf16buf[out++] = c; continue; } |
|
1730 | ||
1731 | c_len = _utf8len[c]; |
|
1732 | // skip 5 & 6 byte codes |
|
1733 | if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; } |
|
1734 | ||
1735 | // apply mask on first byte |
|
1736 | c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; |
|
1737 | // join the rest |
|
1738 | while (c_len > 1 && i < len) { |
|
1739 | c = (c << 6) | (buf[i++] & 0x3f); |
|
1740 | c_len--; |
|
1741 | } |
|
1742 | ||
1743 | // terminated by end of string? |
|
1744 | if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; } |
|
1745 | ||
1746 | if (c < 0x10000) { |
|
1747 | utf16buf[out++] = c; |
|
1748 | } else { |
|
1749 | c -= 0x10000; |
|
1750 | utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff); |
|
1751 | utf16buf[out++] = 0xdc00 | (c & 0x3ff); |
|
1752 | } |
|
1753 | } |
|
1754 | ||
1755 | // shrinkBuf(utf16buf, out) |
|
1756 | if (utf16buf.length !== out) { |