[Pkg-javascript-commits] [ltx] 253/469: Update lib/sax_easysax.js
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:09 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit ba268940004d208067b2591fd2e83b47440d09b9
Author: Vopilovsky Constantine <flash.vkv at gmail.com>
Date: Fri Feb 1 12:50:31 2013 +0400
Update lib/sax_easysax.js
up. easysax designed for small files
---
lib/sax_easysax.js | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/lib/sax_easysax.js b/lib/sax_easysax.js
index a8b7f60..71231cb 100644
--- a/lib/sax_easysax.js
+++ b/lib/sax_easysax.js
@@ -5,16 +5,28 @@ var Easysax = require('easysax');
/**
* FIXME: This SAX parser cannot be pushed to!
*/
-var SaxEasysax = module.exports = function SaxEasysax() {
+module.exports = SaxEasysax;
+util.inherits(SaxEasysax, events.EventEmitter);
+
+
+function SaxEasysax() {
events.EventEmitter.call(this);
this.parser = new Easysax();
+
var that = this;
- this.parser.on('startNode', function(name, attr, uq, str, tagend) {
+
+ this.parser.on('startNode', function(name, attr, uq, istagend) {
attr = attr();
- for(var k in attr)
- if (attr.hasOwnProperty(k)) {
+
+ if (attr === false) {
+ that.emit('error', 'attr char');
+ return false;
+ };
+
+ for(var k in attr) {
attr[k] = uq(attr[k]);
- }
+ };
+
that.emit('startElement', name, attr);
});
this.parser.on('endNode', function(name, uq, str, tagstart) {
@@ -30,16 +42,19 @@ var SaxEasysax = module.exports = function SaxEasysax() {
that.emit('error', e);
});
// TODO: other events, esp. entityDecl (billion laughs!)
-};
-util.inherits(SaxEasysax, events.EventEmitter);
+
+ var sbuffer = '';
+
+ this.write = function(data) {
+ sbuffer += typeof data !== 'string' ? data.toString() : data;
+ };
-SaxEasysax.prototype.write = function(data) {
- if (typeof data !== 'string')
- data = data.toString();
- this.parser.parse(data);
+ this.end = function(data) {
+ sbuffer += typeof data !== 'string' ? data.toString() : data;
+ this.parser(sbuffer);
+ sbuffer = '';
+ };
};
-SaxEasysax.prototype.end = function(data) {
- if (data)
- this.write(data);
-};
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list