[Pkg-javascript-commits] [node-expat] 19/371: xmlDecl callback

Jonas Smedegaard dr at jones.dk
Sun Feb 28 09:59:40 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 f75f0c2fe0f3e589ff11e7c78e7442a5bcf50f62
Author: Astro <astro at spaceboyz.net>
Date:   Sun May 30 14:22:28 2010 +0200

    xmlDecl callback
---
 expat.cc | 20 ++++++++++++++++++--
 test.js  |  5 +++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/expat.cc b/expat.cc
index f2737e9..9f8cee9 100644
--- a/expat.cc
+++ b/expat.cc
@@ -8,7 +8,8 @@ using namespace v8;
 using namespace node;
 
 static Persistent<String> sym_startElement, sym_endElement,
-  sym_text, sym_processingInstruction, sym_comment;
+  sym_text, sym_processingInstruction,
+  sym_comment, sym_xmlDecl;
 
 class Parser : public EventEmitter {
 public:
@@ -30,6 +31,7 @@ public:
     sym_text = NODE_PSYMBOL("text");
     sym_processingInstruction = NODE_PSYMBOL("processingInstruction");
     sym_comment = NODE_PSYMBOL("comment");
+    sym_xmlDecl = NODE_PSYMBOL("xmlDecl");
   }
 
 protected:
@@ -61,6 +63,7 @@ protected:
     XML_SetCharacterDataHandler(parser, Text);
     XML_SetProcessingInstructionHandler(parser, ProcessingInstruction);
     XML_SetCommentHandler(parser, Comment);
+    XML_SetXmlDeclHandler(parser, XmlDecl);
   }
 
   ~Parser()
@@ -188,9 +191,22 @@ private:
     Parser *parser = reinterpret_cast<Parser *>(userData);
 
     /* Trigger event */
-    Handle<Value> argv[1] = { String::New(data)  };
+    Handle<Value> argv[1] = { String::New(data) };
     parser->Emit(sym_comment, 1, argv);
   }
+
+  static void XmlDecl(void *userData,
+                      const XML_Char *version, const XML_Char *encoding,
+                      int standalone)
+  {
+    Parser *parser = reinterpret_cast<Parser *>(userData);
+
+    /* Trigger event */
+    Handle<Value> argv[3] = { String::New(version),
+                              String::New(encoding),
+                              Boolean::New(standalone) };
+    parser->Emit(sym_xmlDecl, 3, argv);
+  }
 };
 
 
diff --git a/test.js b/test.js
index c5dcf65..cc2cbd3 100644
--- a/test.js
+++ b/test.js
@@ -42,6 +42,9 @@ function expect(s, evs_expected) {
 	p.addListener('comment', function(s) {
 	    evs_received.push(['comment', s]);
 	});
+	p.addListener('xmlDecl', function(version, encoding, standalone) {
+	    evs_received.push(['xmlDecl', version, encoding, standalone]);
+	});
 	for(var l = 0; l < s.length; l += step)
 	{
 	    if (!p.parse(s.substr(l, step), false))
@@ -97,5 +100,7 @@ expect("<?i like xml?>",
 expect("<!-- no comment -->",
        [['comment', ' no comment ']]);
 expect("<&", [['error']]);
+expect("<?xml version='1.0' encoding='UTF-8'?>",
+       [['xmlDecl', '1.0', 'UTF-8', true]]);
 
 sys.puts("Ran "+tests+" tests with "+iterations+" iterations: "+fails+" failures.");

-- 
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