/usr/local/lib/node_modules/pm2/node_modules/sax/lib
Edit: /usr/local/lib/node_modules/pm2/node_modules/sax/lib/sax.js (50146B)
;(function (sax) {
// wrapper for non-node envs
sax.parser = function (strict, opt) {
return new SAXParser(strict, opt)
}
sax.SAXParser = SAXParser
sax.SAXStream = SAXStream
sax.createStream = createStream
// When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns.
// When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)),
// since that's the earliest that a buffer overrun could occur. This way, checks are
// as rare as required, but as often as necessary to ensure never crossing this bound.
// Furthermore, buffers are only tested at most once per write(), so passing a very
// large string into write() might have undesirable effects, but this is manageable by
// the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme
// edge case, result in creating at most one complete copy of the string passed in.
// Set to Infinity to have unlimited buffers.
sax.MAX_BUFFER_LENGTH = 64 * 1024
var buffers = [
'comment',
'sgmlDecl',
'textNode',
'tagName',
'doctype',
'procInstName',
'procInstBody',
'entity',
'attribName',
'attribValue',
'cdata',
'script',
]
sax.EVENTS = [
'text',
'processinginstruction',
'sgmldeclaration',
'doctype',
'comment',
'opentagstart',
'attribute',
'opentag',
'closetag',
'opencdata',
'cdata',
'closecdata',
'error',
'end',
'ready',
'script',
'opennamespace',
'closenamespace',
]
function SAXParser(strict, opt) {
if (!(this instanceof SAXParser)) {
return new SAXParser(strict, opt)
}
var parser = this
clearBuffers(parser)
parser.q = parser.c = ''
parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH
parser.encoding = null;
parser.opt = opt || {}
parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags
parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase'
parser.opt.maxEntityCount = parser.opt.maxEntityCount || 512
parser.opt.maxEntityDepth = parser.opt.maxEntityDepth || 4
parser.entityCount = parser.entityDepth = 0
parser.tags = []
parser.closed = parser.closedRoot = parser.sawRoot = false
parser.tag = parser.error = null
parser.strict = !!strict
parser.noscript = !!(strict || parser.opt.noscript)
parser.state = S.BEGIN
parser.strictEntities = parser.opt.strictEntities
parser.ENTITIES =
parser.strictEntities ?
Object.create(sax.XML_ENTITIES)
: Object.create(sax.ENTITIES)
parser.attribList = []
// namespaces form a prototype chain.
// it always points at the current tag,
// which protos to its parent tag.
if (parser.opt.xmlns) {
parser.ns = Object.create(rootNS)
}
// disallow unquoted attribute values if not otherwise configured
// and strict mode is true
if (parser.opt.unquotedAttributeValues === undefined) {
parser.opt.unquotedAttributeValues = !strict
}
// mostly just for error reporting
parser.trackPosition = parser.opt.position !== false
if (parser.trackPosition) {
parser.position = parser.line = parser.column = 0
}
emit(parser, 'onready')
}
if (!Object.create) {
Object.create = function (o) {
function F() {}
F.prototype = o
var newf = new F()
return newf
}
}
if (!Object.keys) {
Object.keys = function (o) {
var a = []
for (var i in o) if (o.hasOwnProperty(i)) a.push(i)
return a
}
}
function checkBufferLength(parser) {
var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)
var maxActual = 0
for (var i = 0, l = buffers.length; i < l; i++) {
var len = parser[buffers[i]].length
if (len > maxAllowed) {
// Text/cdata nodes can get big, and since they're buffered,
// we can get here under normal conditions.
// Avoid issues by emitting the text node now,
// so at least it won't get any bigger.
switch (buffers[i]) {
case 'textNode':
closeText(parser)
break
case 'cdata':
emitNode(parser, 'oncdata', parser.cdata)
parser.cdata = ''
break
case 'script':
emitNode(parser, 'onscript', parser.script)
parser.script = ''
break
default:
error(parser, 'Max buffer length exceeded: ' + buffers[i])
}
}
maxActual = Math.max(maxActual, len)
}
// schedule the next check for the earliest possible buffer overrun.
var m = sax.MAX_BUFFER_LENGTH - maxActual
parser.bufferCheckPosition = m + parser.position
}
function clearBuffers(parser) {
for (var i = 0, l = buffers.length; i < l; i++) {
parser[buffers[i]] = ''
}
}
function flushBuffers(parser) {
closeText(parser)
if (parser.cdata !== '') {
emitNode(parser, 'oncdata', parser.cdata)
parser.cdata = ''
}
if (parser.script !== '') {
emitNode(parser, 'onscript', parser.script)
parser.script = ''
}
}
SAXParser.prototype = {
end: function () {
end(this)
},
write: write,
resume: function () {
this.error = null
return this
},
close: function () {
return this.write(null)
},
flush: function () {
flushBuffers(this)
},
}
var Stream
try {
Stream = require('stream').Stream
} catch (ex) {
Stream = function () {}
}
if (!Stream) Stream = function () {}
var streamWraps = sax.EVENTS.filter(function (ev) {
return ev !== 'error' && ev !== 'end'
})
function createStream(strict, opt) {
return new SAXStream(strict, opt)
}
function determineBufferEncoding(data, isEnd) {
// BOM-based detection is the most reliable signal when present.
if (data.length >= 2) {
if (data[0] === 0xff && data[1] === 0xfe) {
return 'utf-16le'
}
if (data[0] === 0xfe && data[1] === 0xff) {
return 'utf-16be'
}
}
if (data.length >= 3 && data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
return 'utf8'
}
if (data.length >= 4) {
// XML documents without a BOM still start with "' || isWhitespace(c)
}
function isMatch(regex, c) {
return regex.test(c)
}
function notMatch(regex, c) {
return !isMatch(regex, c)
}
var S = 0
sax.STATE = {
BEGIN: S++, // leading byte order mark or whitespace
BEGIN_WHITESPACE: S++, // leading whitespace
TEXT: S++, // general stuff
TEXT_ENTITY: S++, // & and such.
OPEN_WAKA: S++, // <
SGML_DECL: S++, //
SCRIPT: S++, //