(bytes: Uint8Array)
| 101 | * Decode UTF-16BE bytes to string (skips BOM if present). |
| 102 | */ |
| 103 | export function decodeUtf16BE(bytes: Uint8Array): string { |
| 104 | const start = hasUtf16BOM(bytes) ? 2 : 0; |
| 105 | |
| 106 | const chars: string[] = []; |
| 107 | |
| 108 | for (let i = start; i < bytes.length - 1; i += 2) { |
| 109 | const code = (bytes[i] << 8) | bytes[i + 1]; |
| 110 | |
| 111 | // Handle surrogate pairs |
| 112 | if (code >= 0xd800 && code <= 0xdbff && i + 3 < bytes.length) { |
| 113 | const low = (bytes[i + 2] << 8) | bytes[i + 3]; |
| 114 | |
| 115 | if (low >= 0xdc00 && low <= 0xdfff) { |
| 116 | const codePoint = 0x10000 + ((code - 0xd800) << 10) + (low - 0xdc00); |
| 117 | chars.push(String.fromCodePoint(codePoint)); |
| 118 | |
| 119 | i += 2; |
| 120 | |
| 121 | continue; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | chars.push(String.fromCharCode(code)); |
| 126 | } |
| 127 | |
| 128 | return chars.join(""); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Decode PDFDocEncoding bytes to string. |
no test coverage detected