function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end)
- var firstByte
- var secondByte
- var thirdByte
- var fourthByte
- var bytesPerSequence
- var tempCodePoint
- var codePoint
var res = []
- for (var i = start; i < end; i += bytesPerSequence) {
- firstByte = buf[i]
- codePoint = 0xFFFD
-
- if (firstByte > 0xEF) {
- bytesPerSequence = 4
- } else if (firstByte > 0xDF) {
- bytesPerSequence = 3
- } else if (firstByte > 0xBF) {
- bytesPerSequence = 2
- } else {
- bytesPerSequence = 1
- }
+ var i = start
+ while (i < end) {
+ var firstByte = buf[i]
+ var codePoint = 0xFFFD
+ var bytesPerSequence = (firstByte > 0xEF) ? 4
+ : (firstByte > 0xDF) ? 3
+ : (firstByte > 0xBF) ? 2
+ : 1
if (i + bytesPerSequence <= end) {
+ var secondByte, thirdByte, fourthByte, tempCodePoint
+
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
}
res.push(codePoint)
+ i += bytesPerSequence
}
return decodeCodePointsArray(res)