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

Method toUnicode

src/fontbox/cmap/cmap.ts:86–108  ·  view source on GitHub ↗

* Map a character code to Unicode. * * This convenience method tries to determine the code length automatically. * For more accurate results, use toUnicodeWithLength. * * @param code Character code value * @returns Unicode string, or undefined if not mapped

(code: number)

Source from the content-addressed store, hash-verified

84 * @returns Unicode string, or undefined if not mapped
85 */
86 toUnicode(code: number): string | undefined {
87 // Try one byte first for small values
88 if (code < 256) {
89 const result = this.toUnicodeWithLength(code, 1);
90
91 if (result !== undefined) {
92 return result;
93 }
94 }
95
96 // Try two bytes
97 if (code <= 0xffff) {
98 return this.toUnicodeWithLength(code, 2);
99 }
100
101 // Try three bytes
102 if (code <= 0xffffff) {
103 return this.toUnicodeWithLength(code, 3);
104 }
105
106 // Try four bytes
107 return this.toUnicodeWithLength(code, 4);
108 }
109
110 /**
111 * Map a character code to Unicode with explicit length.

Callers 2

parser.test.tsFile · 0.45
showStringMethod · 0.45

Calls 1

toUnicodeWithLengthMethod · 0.95

Tested by

no test coverage detected