All files / buffers/src/utf8/decodeUtf8 v5.ts

95.83% Statements 23/24
88.88% Branches 8/9
100% Functions 1/1
95.83% Lines 23/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 5x 5x 5x 5x 33438x 33438x 33430x 8x 3x 5x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x         5x    
export default (uint8: Uint8Array, start: number, length: number): string => {
  const end = start + length;
  let x = start;
  let str = '';
  while (x < end) {
    const b1 = uint8[x++]!;
    if ((b1 & 0x80) === 0) {
      str += String.fromCharCode(b1);
    } else if ((b1 & 0xe0) === 0xc0) {
      str += String.fromCharCode(((b1 & 0x1f) << 6) | (uint8[x++]! & 0x3f));
    } else if ((b1 & 0xf0) === 0xe0) {
      str += String.fromCharCode(((b1 & 0x1f) << 12) | ((uint8[x++]! & 0x3f) << 6) | (uint8[x++]! & 0x3f));
    } else if ((b1 & 0xf8) === 0xf0) {
      const b2 = uint8[x++]! & 0x3f;
      const b3 = uint8[x++]! & 0x3f;
      const b4 = uint8[x++]! & 0x3f;
      let code = ((b1 & 0x07) << 0x12) | (b2 << 0x0c) | (b3 << 0x06) | b4;
      if (code > 0xffff) {
        code -= 0x10000;
        str += String.fromCharCode(((code >>> 10) & 0x3ff) | 0xd800);
        code = 0xdc00 | (code & 0x3ff);
      }
      str += String.fromCharCode(code);
    } else E{
      str += String.fromCharCode(b1);
    }
  }
  return str;
};