|
@@ 3644-3663 (lines=20) @@
|
| 3641 |
|
// |
| 3642 |
|
// buf[] - utf8 bytes array |
| 3643 |
|
// max - length limit (mandatory); |
| 3644 |
|
exports.utf8border = function(buf, max) { |
| 3645 |
|
var pos; |
| 3646 |
|
|
| 3647 |
|
max = max || buf.length; |
| 3648 |
|
if (max > buf.length) { max = buf.length; } |
| 3649 |
|
|
| 3650 |
|
// go back from last position, until start of sequence found |
| 3651 |
|
pos = max-1; |
| 3652 |
|
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; } |
| 3653 |
|
|
| 3654 |
|
// Fuckup - very small and broken sequence, |
| 3655 |
|
// return max, because we should return something anyway. |
| 3656 |
|
if (pos < 0) { return max; } |
| 3657 |
|
|
| 3658 |
|
// If we came to start of buffer - that means vuffer is too small, |
| 3659 |
|
// return max too. |
| 3660 |
|
if (pos === 0) { return max; } |
| 3661 |
|
|
| 3662 |
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max; |
| 3663 |
|
}; |
| 3664 |
|
|
| 3665 |
|
},{"./common":27}],29:[function(_dereq_,module,exports){ |
| 3666 |
|
'use strict'; |
|
@@ 1695-1714 (lines=20) @@
|
| 1692 |
|
// |
| 1693 |
|
// buf[] - utf8 bytes array |
| 1694 |
|
// max - length limit (mandatory); |
| 1695 |
|
var utf8border = function(buf, max) { |
| 1696 |
|
var pos; |
| 1697 |
|
|
| 1698 |
|
max = max || buf.length; |
| 1699 |
|
if (max > buf.length) { max = buf.length; } |
| 1700 |
|
|
| 1701 |
|
// go back from last position, until start of sequence found |
| 1702 |
|
pos = max-1; |
| 1703 |
|
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; } |
| 1704 |
|
|
| 1705 |
|
// Fuckup - very small and broken sequence, |
| 1706 |
|
// return max, because we should return something anyway. |
| 1707 |
|
if (pos < 0) { return max; } |
| 1708 |
|
|
| 1709 |
|
// If we came to start of buffer - that means vuffer is too small, |
| 1710 |
|
// return max too. |
| 1711 |
|
if (pos === 0) { return max; } |
| 1712 |
|
|
| 1713 |
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max; |
| 1714 |
|
}; |
| 1715 |
|
|
| 1716 |
|
// convert array to string |
| 1717 |
|
var buf2string = function (buf) { |