[Pkg-javascript-commits] [node-expat] 136/371: Imported Upstream version 1.4.5

Jonas Smedegaard dr at jones.dk
Sun Feb 28 09:59:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-expat.

commit 9e29e29f7ac9a0209736d39c3e15a9714a5ea7c0
Author: Jonas Smedegaard <dr at jones.dk>
Date:   Thu Apr 5 12:36:39 2012 +0200

    Imported Upstream version 1.4.5
---
 lib/node-expat.js |  9 +++++++++
 node-expat.cc     | 42 ++++++++++++++++++++++++++++++++++++++++++
 package.json      |  2 +-
 test.js           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/lib/node-expat.js b/lib/node-expat.js
index cad557f..765515e 100644
--- a/lib/node-expat.js
+++ b/lib/node-expat.js
@@ -40,3 +40,12 @@ exports.Parser.prototype.pause = function() {
 exports.Parser.prototype.resume = function() {
     return this.parser.resume();
 };
+exports.Parser.prototype.getCurrentLineNumber = function() {
+    return this.parser.getCurrentLineNumber();
+};
+exports.Parser.prototype.getCurrentColumnNumber = function() {
+    return this.parser.getCurrentColumnNumber();
+};
+exports.Parser.prototype.getCurrentByteIndex = function() {
+    return this.parser.getCurrentByteIndex();
+};
diff --git a/node-expat.cc b/node-expat.cc
index 35b39be..c35b3b2 100644
--- a/node-expat.cc
+++ b/node-expat.cc
@@ -29,6 +29,9 @@ public:
     NODE_SET_PROTOTYPE_METHOD(t, "getError", GetError);
     NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
     NODE_SET_PROTOTYPE_METHOD(t, "resume", Resume);
+    NODE_SET_PROTOTYPE_METHOD(t, "getCurrentLineNumber", GetCurrentLineNumber);
+    NODE_SET_PROTOTYPE_METHOD(t, "getCurrentColumnNumber", GetCurrentColumnNumber);
+    NODE_SET_PROTOTYPE_METHOD(t, "getCurrentByteIndex", GetCurrentByteIndex);
 
     target->Set(String::NewSymbol("Parser"), t->GetFunction());
 
@@ -239,6 +242,45 @@ protected:
     return XML_ErrorString(code);
   }
 
+  static Handle<Value> GetCurrentLineNumber(const Arguments& args)
+  {
+    Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+    HandleScope scope;
+
+    return scope.Close(Integer::NewFromUnsigned(parser->getCurrentLineNumber()));
+  }
+
+  uint32_t getCurrentLineNumber()
+  {
+    return XML_GetCurrentLineNumber(parser);
+  }
+
+  static Handle<Value> GetCurrentColumnNumber(const Arguments& args)
+  {
+    Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+    HandleScope scope;
+
+    return scope.Close(Integer::NewFromUnsigned(parser->getCurrentColumnNumber()));
+  }
+
+  uint32_t getCurrentColumnNumber()
+  {
+    return XML_GetCurrentColumnNumber(parser);
+  }
+
+  static Handle<Value> GetCurrentByteIndex(const Arguments& args)
+  {
+    Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+    HandleScope scope;
+
+    return scope.Close(Integer::New(parser->getCurrentByteIndex()));
+  }
+
+  int32_t getCurrentByteIndex()
+  {
+    return XML_GetCurrentByteIndex(parser);
+  }
+
 private:
   /* expat instance */
   XML_Parser parser;
diff --git a/package.json b/package.json
index f97163e..00672d2 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 { "name": "node-expat"
-,"version": "1.4.3"
+,"version": "1.4.5"
 ,"main": "./lib/node-expat"
 ,"description": "NodeJS binding for fast XML parsing."
 ,"keywords": ["xml","sax","expat","libexpat","parse","parsing"]
diff --git a/test.js b/test.js
index 1508407..6b5a2dd 100644
--- a/test.js
+++ b/test.js
@@ -249,5 +249,35 @@ vows.describe('node-expat').addBatch({
            assert.ok(result2);
 
         }*/
+    },
+    'statistics': {
+	'line number': function() {
+	    var p = new expat.Parser();
+	    assert.equal(p.getCurrentLineNumber(), 1);
+	    p.parse("\n");
+	    assert.equal(p.getCurrentLineNumber(), 2);
+	    p.parse("\n");
+	    assert.equal(p.getCurrentLineNumber(), 3);
+	},
+	'column number': function() {
+	    var p = new expat.Parser();
+	    assert.equal(p.getCurrentColumnNumber(), 0);
+	    p.parse(" ");
+	    assert.equal(p.getCurrentColumnNumber(), 1);
+	    p.parse(" ");
+	    assert.equal(p.getCurrentColumnNumber(), 2);
+	    p.parse("\n");
+	    assert.equal(p.getCurrentColumnNumber(), 0);
+	},
+	'byte index': function() {
+	    var p = new expat.Parser();
+	    assert.equal(p.getCurrentByteIndex(), -1);
+	    p.parse("");
+	    assert.equal(p.getCurrentByteIndex(), -1);
+	    p.parse("\n");
+	    assert.equal(p.getCurrentByteIndex(), 1);
+	    p.parse(" ");
+	    assert.equal(p.getCurrentByteIndex(), 2);
+	},
     }
 }).export(module);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git



More information about the Pkg-javascript-commits mailing list