[Pkg-javascript-commits] [node-expat] 03/371: emit text event
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:39 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 8ed0e795c6d2804a5f436ff8ed83de91bf0b2956
Author: Astro <astro at spaceboyz.net>
Date: Sat May 22 15:10:38 2010 +0200
emit text event
---
expat.cc | 14 +++++++++++++-
test.js | 14 ++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/expat.cc b/expat.cc
index bae878e..addeded 100644
--- a/expat.cc
+++ b/expat.cc
@@ -9,8 +9,9 @@ using namespace node;
static void StartElement(void *userData, const XML_Char *name, const XML_Char **atts);
static void EndElement(void *userData, const XML_Char *name);
+static void Text(void *userData, const XML_Char *s, int len);
-static Persistent<String> sym_startElement, sym_endElement;
+static Persistent<String> sym_startElement, sym_endElement, sym_text;
class Parser : public EventEmitter {
public:
@@ -29,6 +30,7 @@ public:
sym_startElement = NODE_PSYMBOL("startElement");
sym_endElement = NODE_PSYMBOL("endElement");
+ sym_text = NODE_PSYMBOL("text");
}
protected:
@@ -50,6 +52,7 @@ protected:
XML_SetUserData(parser, this);
XML_SetElementHandler(parser, StartElement, EndElement);
+ XML_SetCharacterDataHandler(parser, Text);
}
~Parser()
@@ -124,6 +127,15 @@ static void EndElement(void *userData, const XML_Char *name)
parser->Emit(sym_endElement, 1, argv);
}
+static void Text(void *userData, const XML_Char *s, int len)
+{
+ Parser *parser = reinterpret_cast<Parser *>(userData);
+
+ /* Trigger event */
+ Handle<Value> argv[1] = { String::New(s, len) };
+ parser->Emit(sym_text, 1, argv);
+}
+
extern "C" void init(Handle<Object> target)
{
diff --git a/test.js b/test.js
index fc4db89..1625d96 100644
--- a/test.js
+++ b/test.js
@@ -39,3 +39,17 @@ expect("<r foo='bar' baz=\"quux\" test=\"tset\"/>",
expect("<r xmlns='http://localhost/' xmlns:x=\"http://example.com/\"></r>",
[['startElement', 'r', {xmlns: 'http://localhost/', 'xmlns:x': 'http://example.com/'}],
['endElement', 'r']]);
+expect("<r>foo</r>",
+ [['startElement', 'r', {}],
+ ['text', "foo"],
+ ['endElement', 'r']]);
+expect("<r>foo\nbar</r>",
+ [['startElement', 'r', {}],
+ ['text', "foo"],
+ ['text', "\n"],
+ ['text', "bar"],
+ ['endElement', 'r']]);
+expect("<r><![CDATA[<greeting>Hello, world!</greeting>]]></r>",
+ [['startElement', 'r', {}],
+ ['text', "<greeting>Hello, world!</greeting>"],
+ ['endElement', 'r']]);
--
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