(bytes: Uint8Array, littleEndian: boolean)
| 18 | } |
| 19 | |
| 20 | function decodeUTF16(bytes: Uint8Array, littleEndian: boolean) { |
| 21 | const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); |
| 22 | let out = ""; |
| 23 | for (let i = 0; i + 2 <= dv.byteLength; ) { |
| 24 | const w1 = dv.getUint16(i, littleEndian); |
| 25 | i += 2; |
| 26 | if (w1 >= 0xd800 && w1 <= 0xdbff && i + 2 <= dv.byteLength) { |
| 27 | const w2 = dv.getUint16(i, littleEndian); |
| 28 | i += 2; |
| 29 | const cp = (((w1 - 0xd800) << 10) | (w2 - 0xdc00)) + 0x10000; |
| 30 | out += String.fromCodePoint(cp); |
| 31 | } else { |
| 32 | out += String.fromCharCode(w1); |
| 33 | } |
| 34 | } |
| 35 | return out; |
| 36 | } |
| 37 | |
| 38 | function encodeUTF16(str: string, littleEndian: boolean, addBOM = false) { |
| 39 | // count code units |
no outgoing calls
no test coverage detected
searching dependent graphs…