(data: Buffer)
| 5 | } |
| 6 | |
| 7 | function decodeUtf8Ignore(data: Buffer): string { |
| 8 | let output = ''; |
| 9 | let i = 0; |
| 10 | |
| 11 | while (i < data.length) { |
| 12 | const b0 = data[i]; |
| 13 | if (b0 === undefined) break; |
| 14 | |
| 15 | if (b0 <= 0x7f) { |
| 16 | output += String.fromCodePoint(b0); |
| 17 | i += 1; |
| 18 | continue; |
| 19 | } |
| 20 | |
| 21 | if (b0 >= 0xc2 && b0 <= 0xdf) { |
| 22 | const b1 = data[i + 1]; |
| 23 | if (b1 !== undefined && isUtf8Continuation(b1)) { |
| 24 | output += String.fromCodePoint(((b0 & 0x1f) << 6) | (b1 & 0x3f)); |
| 25 | i += 2; |
| 26 | continue; |
| 27 | } |
| 28 | i += 1; |
| 29 | continue; |
| 30 | } |
| 31 | |
| 32 | if (b0 >= 0xe0 && b0 <= 0xef) { |
| 33 | const b1 = data[i + 1]; |
| 34 | const b2 = data[i + 2]; |
| 35 | const validSecond = |
| 36 | b1 !== undefined && |
| 37 | ((b0 === 0xe0 && b1 >= 0xa0 && b1 <= 0xbf) || |
| 38 | (b0 >= 0xe1 && b0 <= 0xec && isUtf8Continuation(b1)) || |
| 39 | (b0 === 0xed && b1 >= 0x80 && b1 <= 0x9f) || |
| 40 | (b0 >= 0xee && b0 <= 0xef && isUtf8Continuation(b1))); |
| 41 | |
| 42 | if (validSecond && b2 !== undefined && isUtf8Continuation(b2)) { |
| 43 | output += String.fromCodePoint(((b0 & 0x0f) << 12) | ((b1 & 0x3f) << 6) | (b2 & 0x3f)); |
| 44 | i += 3; |
| 45 | continue; |
| 46 | } |
| 47 | i += 1; |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | if (b0 >= 0xf0 && b0 <= 0xf4) { |
| 52 | const b1 = data[i + 1]; |
| 53 | const b2 = data[i + 2]; |
| 54 | const b3 = data[i + 3]; |
| 55 | const validSecond = |
| 56 | b1 !== undefined && |
| 57 | ((b0 === 0xf0 && b1 >= 0x90 && b1 <= 0xbf) || |
| 58 | (b0 >= 0xf1 && b0 <= 0xf3 && isUtf8Continuation(b1)) || |
| 59 | (b0 === 0xf4 && b1 >= 0x80 && b1 <= 0x8f)); |
| 60 | |
| 61 | if ( |
| 62 | validSecond && |
| 63 | b2 !== undefined && |
| 64 | b3 !== undefined && |
no test coverage detected