Move the isAscii
helper function into the worker-thread
Given that this helper function is only used on the worker-thread, there's no reason to duplicate it in both of the `pdf.js` and `pdf.worker.js` files.
This commit is contained in:
parent
2eaa708e3a
commit
e5859e145d
@ -27,7 +27,6 @@ import {
|
|||||||
FeatureTest,
|
FeatureTest,
|
||||||
getModificationDate,
|
getModificationDate,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
isAscii,
|
|
||||||
LINE_DESCENT_FACTOR,
|
LINE_DESCENT_FACTOR,
|
||||||
LINE_FACTOR,
|
LINE_FACTOR,
|
||||||
OPS,
|
OPS,
|
||||||
@ -42,6 +41,7 @@ import {
|
|||||||
collectActions,
|
collectActions,
|
||||||
getInheritableProperty,
|
getInheritableProperty,
|
||||||
getRotationMatrix,
|
getRotationMatrix,
|
||||||
|
isAscii,
|
||||||
numberToString,
|
numberToString,
|
||||||
stringToUTF16String,
|
stringToUTF16String,
|
||||||
} from "./core_utils.js";
|
} from "./core_utils.js";
|
||||||
|
@ -572,6 +572,10 @@ function getNewAnnotationsMap(annotationStorage) {
|
|||||||
return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
|
return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAscii(str) {
|
||||||
|
return /^[\x00-\x7F]*$/.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
function stringToUTF16HexString(str) {
|
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++) {
|
||||||
@ -622,6 +626,7 @@ export {
|
|||||||
getLookupTableFactory,
|
getLookupTableFactory,
|
||||||
getNewAnnotationsMap,
|
getNewAnnotationsMap,
|
||||||
getRotationMatrix,
|
getRotationMatrix,
|
||||||
|
isAscii,
|
||||||
isWhiteSpace,
|
isWhiteSpace,
|
||||||
log2,
|
log2,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
|
@ -1051,10 +1051,6 @@ function escapeString(str) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAscii(str) {
|
|
||||||
return /^[\x00-\x7F]*$/.test(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function stringToUTF8String(str) {
|
function stringToUTF8String(str) {
|
||||||
return decodeURIComponent(escape(str));
|
return decodeURIComponent(escape(str));
|
||||||
}
|
}
|
||||||
@ -1168,7 +1164,6 @@ export {
|
|||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
isArrayEqual,
|
isArrayEqual,
|
||||||
isAscii,
|
|
||||||
LINE_DESCENT_FACTOR,
|
LINE_DESCENT_FACTOR,
|
||||||
LINE_FACTOR,
|
LINE_FACTOR,
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
encodeToXmlString,
|
encodeToXmlString,
|
||||||
escapePDFName,
|
escapePDFName,
|
||||||
getInheritableProperty,
|
getInheritableProperty,
|
||||||
|
isAscii,
|
||||||
isWhiteSpace,
|
isWhiteSpace,
|
||||||
log2,
|
log2,
|
||||||
parseXFAPath,
|
parseXFAPath,
|
||||||
@ -335,6 +336,16 @@ describe("core_utils", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("isAscii", function () {
|
||||||
|
it("handles ascii/non-ascii strings", function () {
|
||||||
|
expect(isAscii("hello world")).toEqual(true);
|
||||||
|
expect(isAscii("こんにちは世界の")).toEqual(false);
|
||||||
|
expect(isAscii("hello world in Japanese is こんにちは世界の")).toEqual(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("stringToUTF16String", function () {
|
describe("stringToUTF16String", function () {
|
||||||
it("should encode a string in UTF16", function () {
|
it("should encode a string in UTF16", function () {
|
||||||
expect(stringToUTF16String("hello world")).toEqual(
|
expect(stringToUTF16String("hello world")).toEqual(
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
escapeString,
|
escapeString,
|
||||||
getModificationDate,
|
getModificationDate,
|
||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
isAscii,
|
|
||||||
string32,
|
string32,
|
||||||
stringToBytes,
|
stringToBytes,
|
||||||
stringToPDFString,
|
stringToPDFString,
|
||||||
@ -259,14 +258,4 @@ describe("util", function () {
|
|||||||
expect(getModificationDate(date)).toEqual("31410609020653");
|
expect(getModificationDate(date)).toEqual("31410609020653");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isAscii", function () {
|
|
||||||
it("handles ascii/non-ascii strings", function () {
|
|
||||||
expect(isAscii("hello world")).toEqual(true);
|
|
||||||
expect(isAscii("こんにちは世界の")).toEqual(false);
|
|
||||||
expect(isAscii("hello world in Japanese is こんにちは世界の")).toEqual(
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user