Use the hexNumbers structure in the stringToUTF16HexString helper

We can re-use the `hexNumbers` structure here, since that allows us to directly lookup the hexadecimal values and shortens the code.
This commit is contained in:
Jonas Jenwald 2024-11-02 15:00:32 +01:00
parent 06f3b2d0a6
commit 2145a7b9ca
2 changed files with 3 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import {
AnnotationEditorPrefix, AnnotationEditorPrefix,
assert, assert,
BaseException, BaseException,
hexNumbers,
objectSize, objectSize,
stringToPDFString, stringToPDFString,
Util, Util,
@ -634,10 +635,7 @@ function stringToUTF16HexString(str) {
const buf = []; const buf = [];
for (let i = 0, ii = str.length; i < ii; i++) { for (let i = 0, ii = str.length; i < ii; i++) {
const char = str.charCodeAt(i); const char = str.charCodeAt(i);
buf.push( buf.push(hexNumbers[(char >> 8) & 0xff], hexNumbers[char & 0xff]);
((char >> 8) & 0xff).toString(16).padStart(2, "0"),
(char & 0xff).toString(16).padStart(2, "0")
);
} }
return buf.join(""); return buf.join("");
} }

View File

@ -1149,6 +1149,7 @@ export {
getModificationDate, getModificationDate,
getUuid, getUuid,
getVerbosityLevel, getVerbosityLevel,
hexNumbers,
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
info, info,