| "use strict"; |
| Object.defineProperty(exports, "__esModule", { value: true }); |
| exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.getCodePoint = exports.xmlReplacer = void 0; |
| exports.xmlReplacer = /["&'<>$\x80-\uFFFF]/g; |
| var xmlCodeMap = new Map([ |
| [34, """], |
| [38, "&"], |
| [39, "'"], |
| [60, "<"], |
| [62, ">"], |
| ]); |
| |
| exports.getCodePoint = |
| |
| String.prototype.codePointAt != null |
| ? function (str, index) { return str.codePointAt(index); } |
| : |
| function (c, index) { |
| return (c.charCodeAt(index) & 0xfc00) === 0xd800 |
| ? (c.charCodeAt(index) - 0xd800) * 0x400 + |
| c.charCodeAt(index + 1) - |
| 0xdc00 + |
| 0x10000 |
| : c.charCodeAt(index); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| function encodeXML(str) { |
| var ret = ""; |
| var lastIdx = 0; |
| var match; |
| while ((match = exports.xmlReplacer.exec(str)) !== null) { |
| var i = match.index; |
| var char = str.charCodeAt(i); |
| var next = xmlCodeMap.get(char); |
| if (next !== undefined) { |
| ret += str.substring(lastIdx, i) + next; |
| lastIdx = i + 1; |
| } |
| else { |
| ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";"); |
| |
| lastIdx = exports.xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800); |
| } |
| } |
| return ret + str.substr(lastIdx); |
| } |
| exports.encodeXML = encodeXML; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| exports.escape = encodeXML; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function getEscaper(regex, map) { |
| return function escape(data) { |
| var match; |
| var lastIdx = 0; |
| var result = ""; |
| while ((match = regex.exec(data))) { |
| if (lastIdx !== match.index) { |
| result += data.substring(lastIdx, match.index); |
| } |
| |
| result += map.get(match[0].charCodeAt(0)); |
| |
| lastIdx = match.index + 1; |
| } |
| return result + data.substring(lastIdx); |
| }; |
| } |
| |
| |
| |
| |
| |
| |
| |
| exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap); |
| |
| |
| |
| |
| |
| |
| exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([ |
| [34, """], |
| [38, "&"], |
| [160, " "], |
| ])); |
| |
| |
| |
| |
| |
| |
| exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([ |
| [38, "&"], |
| [60, "<"], |
| [62, ">"], |
| [160, " "], |
| ])); |
| |