* 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)
| 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. |
no test coverage detected