| @@ 3529-3557 (lines=29) @@ | ||
| 3526 | buf = new utils.Buf8(buf_len); |
|
| 3527 | ||
| 3528 | // convert |
|
| 3529 | for (i=0, m_pos = 0; i < buf_len; m_pos++) { |
|
| 3530 | c = str.charCodeAt(m_pos); |
|
| 3531 | if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) { |
|
| 3532 | c2 = str.charCodeAt(m_pos+1); |
|
| 3533 | if ((c2 & 0xfc00) === 0xdc00) { |
|
| 3534 | c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); |
|
| 3535 | m_pos++; |
|
| 3536 | } |
|
| 3537 | } |
|
| 3538 | if (c < 0x80) { |
|
| 3539 | /* one byte */ |
|
| 3540 | buf[i++] = c; |
|
| 3541 | } else if (c < 0x800) { |
|
| 3542 | /* two bytes */ |
|
| 3543 | buf[i++] = 0xC0 | (c >>> 6); |
|
| 3544 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 3545 | } else if (c < 0x10000) { |
|
| 3546 | /* three bytes */ |
|
| 3547 | buf[i++] = 0xE0 | (c >>> 12); |
|
| 3548 | buf[i++] = 0x80 | (c >>> 6 & 0x3f); |
|
| 3549 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 3550 | } else { |
|
| 3551 | /* four bytes */ |
|
| 3552 | buf[i++] = 0xf0 | (c >>> 18); |
|
| 3553 | buf[i++] = 0x80 | (c >>> 12 & 0x3f); |
|
| 3554 | buf[i++] = 0x80 | (c >>> 6 & 0x3f); |
|
| 3555 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 3556 | } |
|
| 3557 | } |
|
| 3558 | ||
| 3559 | return buf; |
|
| 3560 | }; |
|
| @@ 1656-1684 (lines=29) @@ | ||
| 1653 | } |
|
| 1654 | ||
| 1655 | // convert |
|
| 1656 | for (i=0, m_pos = 0; i < buf_len; m_pos++) { |
|
| 1657 | c = str.charCodeAt(m_pos); |
|
| 1658 | if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) { |
|
| 1659 | c2 = str.charCodeAt(m_pos+1); |
|
| 1660 | if ((c2 & 0xfc00) === 0xdc00) { |
|
| 1661 | c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); |
|
| 1662 | m_pos++; |
|
| 1663 | } |
|
| 1664 | } |
|
| 1665 | if (c < 0x80) { |
|
| 1666 | /* one byte */ |
|
| 1667 | buf[i++] = c; |
|
| 1668 | } else if (c < 0x800) { |
|
| 1669 | /* two bytes */ |
|
| 1670 | buf[i++] = 0xC0 | (c >>> 6); |
|
| 1671 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 1672 | } else if (c < 0x10000) { |
|
| 1673 | /* three bytes */ |
|
| 1674 | buf[i++] = 0xE0 | (c >>> 12); |
|
| 1675 | buf[i++] = 0x80 | ((c >>> 6) & 0x3f); |
|
| 1676 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 1677 | } else { |
|
| 1678 | /* four bytes */ |
|
| 1679 | buf[i++] = 0xf0 | (c >>> 18); |
|
| 1680 | buf[i++] = 0x80 | ((c >>> 12) & 0x3f); |
|
| 1681 | buf[i++] = 0x80 | ((c >>> 6) & 0x3f); |
|
| 1682 | buf[i++] = 0x80 | (c & 0x3f); |
|
| 1683 | } |
|
| 1684 | } |
|
| 1685 | ||
| 1686 | return buf; |
|
| 1687 | }; |
|