(buf, start, end)
| 950 | } |
| 951 | |
| 952 | function utf8Slice (buf, start, end) { |
| 953 | end = Math.min(buf.length, end) |
| 954 | const res = [] |
| 955 | |
| 956 | let i = start |
| 957 | while (i < end) { |
| 958 | const firstByte = buf[i] |
| 959 | let codePoint = null |
| 960 | let bytesPerSequence = (firstByte > 0xEF) |
| 961 | ? 4 |
| 962 | : (firstByte > 0xDF) |
| 963 | ? 3 |
| 964 | : (firstByte > 0xBF) |
| 965 | ? 2 |
| 966 | : 1 |
| 967 | |
| 968 | if (i + bytesPerSequence <= end) { |
| 969 | let secondByte, thirdByte, fourthByte, tempCodePoint |
| 970 | |
| 971 | switch (bytesPerSequence) { |
| 972 | case 1: |
| 973 | if (firstByte < 0x80) { |
| 974 | codePoint = firstByte |
| 975 | } |
| 976 | break |
| 977 | case 2: |
| 978 | secondByte = buf[i + 1] |
| 979 | if ((secondByte & 0xC0) === 0x80) { |
| 980 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) |
| 981 | if (tempCodePoint > 0x7F) { |
| 982 | codePoint = tempCodePoint |
| 983 | } |
| 984 | } |
| 985 | break |
| 986 | case 3: |
| 987 | secondByte = buf[i + 1] |
| 988 | thirdByte = buf[i + 2] |
| 989 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { |
| 990 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) |
| 991 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { |
| 992 | codePoint = tempCodePoint |
| 993 | } |
| 994 | } |
| 995 | break |
| 996 | case 4: |
| 997 | secondByte = buf[i + 1] |
| 998 | thirdByte = buf[i + 2] |
| 999 | fourthByte = buf[i + 3] |
| 1000 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { |
| 1001 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) |
| 1002 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { |
| 1003 | codePoint = tempCodePoint |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | if (codePoint === null) { |
no test coverage detected
searching dependent graphs…