MCPcopy Create free account
hub / github.com/LibPDF-js/core / createStringFromBytes

Function createStringFromBytes

src/fontbox/cmap/utils.ts:67–87  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

65 * Create string from UTF-16BE bytes.
66 */
67export function createStringFromBytes(bytes: Uint8Array): string {
68 if (bytes.length <= 2) {
69 // Single character - interpret as UTF-16BE code point
70 let code = 0;
71
72 for (let i = 0; i < bytes.length; i++) {
73 code = (code << 8) | bytes[i];
74 }
75
76 return String.fromCharCode(code);
77 }
78
79 // Multi-byte: interpret as UTF-16BE string
80 let result = "";
81
82 for (let i = 0; i + 1 < bytes.length; i += 2) {
83 result += String.fromCharCode((bytes[i] << 8) | bytes[i + 1]);
84 }
85
86 return result;
87}

Callers 3

parseBfCharMethod · 0.90
addBfRangeFromArrayMethod · 0.90
addBfRangeFromBytesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected