(buf: Uint8Array, chunkBegin: number)
| 102 | // @todo add documentation for these |
| 103 | |
| 104 | function getChunkBegin(buf: Uint8Array, chunkBegin: number) { |
| 105 | // If it's the beginning, just return. |
| 106 | if (chunkBegin === 0) { |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | if (!isLaterByteOfUtf8(buf[chunkBegin])) { |
| 111 | return chunkBegin; |
| 112 | } |
| 113 | |
| 114 | let begin = chunkBegin - 3; |
| 115 | |
| 116 | if (begin >= 0) { |
| 117 | if (isFirstByteOf4ByteChar(buf[begin])) { |
| 118 | return begin; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | begin = chunkBegin - 2; |
| 123 | |
| 124 | if (begin >= 0) { |
| 125 | if (isFirstByteOf4ByteChar(buf[begin]) || isFirstByteOf3ByteChar(buf[begin])) { |
| 126 | return begin; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | begin = chunkBegin - 1; |
| 131 | |
| 132 | if (begin >= 0) { |
| 133 | // Is it a 4-byte, 3-byte utf8 character? |
| 134 | if ( |
| 135 | isFirstByteOf4ByteChar(buf[begin]) || |
| 136 | isFirstByteOf3ByteChar(buf[begin]) || |
| 137 | isFirstByteOf2ByteChar(buf[begin]) |
| 138 | ) { |
| 139 | return begin; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return -1; |
| 144 | } |
| 145 | |
| 146 | function getChunkEnd(buf: Uint8Array, chunkEnd: number) { |
| 147 | // If it's the end, just return. |
no test coverage detected