Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
179 additions
and
2,218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
node_modules/ | ||
|
||
ltx.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test/ | ||
|
||
.editorconfig | ||
.gitignore | ||
.jshintrc | ||
.npmignore | ||
.travis.yml | ||
benchmark.js | ||
CONTRIBUTING.md | ||
Gruntfile.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
var benchmark = require('benchmark') | ||
var ltx = require('./lib/index') | ||
var parsers = require('./lib/parsers') | ||
|
||
var XML = [ | ||
'<message to="foo@bar" from="bar@to" type="chat" id="foobar">', | ||
'<body>Where there is love there is life.</body>', | ||
'</message>' | ||
].join('') | ||
|
||
var suite = new benchmark.Suite('parse'); | ||
|
||
parsers.forEach(function(Parser) { | ||
suite.add(Parser.name, function() { | ||
ltx.parse(XML, {Parser: Parser}) | ||
}) | ||
}) | ||
|
||
suite.on('cycle', function(event) { | ||
console.log(event.target.toString()); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | ||
}) | ||
.run({ 'async': true }); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
var EventEmitter = require('events').EventEmitter | ||
var inherits = require('util').inherits | ||
var Element = require('./Element') | ||
var LtxParser = require('./parsers/ltx') | ||
|
||
var Parser = function(options) { | ||
EventEmitter.call(this) | ||
|
||
var ParserInterface = this.Parser = (options && options.Parser) || LtxParser | ||
var ElementInterface = this.Element = (options && options.Element) || Element | ||
|
||
if (!ParserInterface) { | ||
throw new Error('No SAX parser available') | ||
} | ||
this.parser = new ParserInterface() | ||
|
||
var el | ||
, self = this | ||
this.parser.on('startElement', function(name, attrs) { | ||
var child = new ElementInterface(name, attrs) | ||
if (!el) { | ||
el = child | ||
} else { | ||
el = el.cnode(child) | ||
} | ||
}) | ||
this.parser.on('endElement', function(name) { | ||
/* jshint -W035 */ | ||
if (!el) { | ||
/* Err */ | ||
} else if (name === el.name) { | ||
if (el.parent) { | ||
el = el.parent | ||
} else if (!self.tree) { | ||
self.tree = el | ||
el = undefined | ||
} | ||
} | ||
/* jshint +W035 */ | ||
}) | ||
this.parser.on('text', function(str) { | ||
if (el) { | ||
el.t(str) | ||
} | ||
}) | ||
this.parser.on('error', function(e) { | ||
self.error = e | ||
self.emit('error', e) | ||
}) | ||
} | ||
|
||
inherits(Parser, EventEmitter) | ||
|
||
Parser.prototype.write = function(data) { | ||
this.parser.write(data) | ||
} | ||
|
||
Parser.prototype.end = function(data) { | ||
this.parser.end(data) | ||
|
||
if (!this.error) { | ||
if (this.tree) { | ||
this.emit('tree', this.tree) | ||
} else { | ||
this.emit('error', new Error('Incomplete document')) | ||
} | ||
} | ||
} | ||
|
||
module.exports = Parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
module.exports.escapeXML = function escapeXML(s) { | ||
return s. | ||
replace(/\&/g, '&'). | ||
replace(/</g, '<'). | ||
replace(/>/g, '>'). | ||
replace(/"/g, '"'). | ||
replace(/"/g, ''') | ||
} | ||
|
||
module.exports.escapeXMLText = function escapeXMLText(s) { | ||
return s. | ||
replace(/\&/g, '&'). | ||
replace(/</g, '<'). | ||
replace(/>/g, '>') | ||
} |
Oops, something went wrong.