1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

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

@ -21,6 +21,7 @@ import {
isWhiteSpace,
log2,
parseXFAPath,
stringToUTF16String,
toRomanNumerals,
validateCSSFont,
} from "../../src/core/core_utils.js";
@ -333,4 +334,28 @@ describe("core_utils", function () {
expect(cssFontInfo.italicAngle).toEqual("2.718");
});
});
describe("stringToUTF16String", function () {
it("should encode a string in UTF16", function () {
expect(stringToUTF16String("hello world")).toEqual(
"\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d"
);
expect(stringToUTF16String("こんにちは世界の")).toEqual(
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"
);
});
it("should encode a string in UTF16BE with a BOM", function () {
expect(
stringToUTF16String("hello world", /* bigEndian = */ true)
).toEqual("\xfe\xff\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d");
expect(
stringToUTF16String("こんにちは世界の", /* bigEndian = */ true)
).toEqual(
"\xfe\xff\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"
);
});
});
});

View file

@ -24,7 +24,6 @@ import {
string32,
stringToBytes,
stringToPDFString,
stringToUTF16BEString,
} from "../../src/shared/util.js";
describe("util", function () {
@ -270,16 +269,4 @@ describe("util", function () {
);
});
});
describe("stringToUTF16BEString", function () {
it("should encode a string in UTF16BE with a BOM", function () {
expect(stringToUTF16BEString("hello world")).toEqual(
"\xfe\xff\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d"
);
expect(stringToUTF16BEString("こんにちは世界の")).toEqual(
"\xfe\xff\x30\x53\x30\x93\x30\x6b\x30\x61" +
"\x30\x6f\x4e\x16\x75\x4c\x30\x6e"
);
});
});
});