Combine the stringToUTF16String and stringToUTF16BEString helper functions

Given that these functions are virtually identical, with the latter only adding a BOM, we can combine the two. Furthermore, since both functions were only used on the worker-thread, there's no reason to duplicate this functionality in both of the `pdf.js` and `pdf.worker.js` files.
This commit is contained in:
Jonas Jenwald 2022-11-16 12:05:00 +01:00
parent c7d6ab2f71
commit 2eaa708e3a
5 changed files with 41 additions and 31 deletions

View file

@ -1055,18 +1055,6 @@ function isAscii(str) {
return /^[\x00-\x7F]*$/.test(str);
}
function stringToUTF16BEString(str) {
const buf = ["\xFE\xFF"];
for (let i = 0, ii = str.length; i < ii; i++) {
const char = str.charCodeAt(i);
buf.push(
String.fromCharCode((char >> 8) & 0xff),
String.fromCharCode(char & 0xff)
);
}
return buf.join("");
}
function stringToUTF8String(str) {
return decodeURIComponent(escape(str));
}
@ -1198,7 +1186,6 @@ export {
string32,
stringToBytes,
stringToPDFString,
stringToUTF16BEString,
stringToUTF8String,
TextRenderingMode,
UnexpectedResponseException,