mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Move the encodeToXmlString
helper function to src/core/core_utils.js
With the previous patch this function is now *only* accessed on the worker-thread, hence it's no longer necessary to include it in the *built* `pdf.js` file.
This commit is contained in:
parent
b66f294f64
commit
d366bbdf51
5 changed files with 62 additions and 64 deletions
|
@ -316,8 +316,54 @@ function collectActions(xref, dict, eventType) {
|
|||
return objectSize(actions) > 0 ? actions : null;
|
||||
}
|
||||
|
||||
const XMLEntities = {
|
||||
/* < */ 0x3c: "<",
|
||||
/* > */ 0x3e: ">",
|
||||
/* & */ 0x26: "&",
|
||||
/* " */ 0x22: """,
|
||||
/* ' */ 0x27: "'",
|
||||
};
|
||||
|
||||
function encodeToXmlString(str) {
|
||||
const buffer = [];
|
||||
let start = 0;
|
||||
for (let i = 0, ii = str.length; i < ii; i++) {
|
||||
const char = str.codePointAt(i);
|
||||
if (0x20 <= char && char <= 0x7e) {
|
||||
// ascii
|
||||
const entity = XMLEntities[char];
|
||||
if (entity) {
|
||||
if (start < i) {
|
||||
buffer.push(str.substring(start, i));
|
||||
}
|
||||
buffer.push(entity);
|
||||
start = i + 1;
|
||||
}
|
||||
} else {
|
||||
if (start < i) {
|
||||
buffer.push(str.substring(start, i));
|
||||
}
|
||||
buffer.push(`&#x${char.toString(16).toUpperCase()};`);
|
||||
if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
|
||||
// char is represented by two u16
|
||||
i++;
|
||||
}
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer.length === 0) {
|
||||
return str;
|
||||
}
|
||||
if (start < str.length) {
|
||||
buffer.push(str.substring(start, str.length));
|
||||
}
|
||||
return buffer.join("");
|
||||
}
|
||||
|
||||
export {
|
||||
collectActions,
|
||||
encodeToXmlString,
|
||||
escapePDFName,
|
||||
getArrayLookupTableFactory,
|
||||
getInheritableProperty,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue