Permalink
Browse files

Exposing XML_ParserReset.

  • Loading branch information...
1 parent 68df853 commit f638c4689d5b1a87c48b6141adc2604ba15e575c @satyamshekhar satyamshekhar committed Apr 8, 2012
Showing with 37 additions and 7 deletions.
  1. +3 −0 lib/node-expat.js
  2. +34 −7 node-expat.cc
View
@@ -40,6 +40,9 @@ exports.Parser.prototype.pause = function() {
exports.Parser.prototype.resume = function() {
return this.parser.resume();
};
+exports.Parser.prototype.reset = function() {
+ return this.parser.reset();
+};
exports.Parser.prototype.getCurrentLineNumber = function() {
return this.parser.getCurrentLineNumber();
};
View
@@ -29,6 +29,7 @@ class Parser : public ObjectWrap {
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, "reset", Reset);
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentLineNumber", GetCurrentLineNumber);
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentColumnNumber", GetCurrentColumnNumber);
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentByteIndex", GetCurrentByteIndex);
@@ -73,6 +74,16 @@ class Parser : public ObjectWrap {
parser = XML_ParserCreate(encoding);
assert(parser != NULL);
+ attachHandlers();
+ }
+
+ ~Parser()
+ {
+ XML_ParserFree(parser);
+ }
+
+ void attachHandlers()
+ {
XML_SetUserData(parser, this);
XML_SetElementHandler(parser, StartElement, EndElement);
XML_SetCharacterDataHandler(parser, Text);
@@ -82,12 +93,7 @@ class Parser : public ObjectWrap {
XML_SetXmlDeclHandler(parser, XmlDecl);
XML_SetEntityDeclHandler(parser, EntityDecl);
}
-
- ~Parser()
- {
- XML_ParserFree(parser);
- }
-
+
/*** parse() ***/
static Handle<Value> Parse(const Arguments& args)
@@ -235,6 +241,27 @@ class Parser : public ObjectWrap {
return XML_ResumeParser(parser) != 0;
}
+ static Handle<Value> Reset(const Arguments& args)
+ {
+ Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+ HandleScope scope;
+ XML_Char *encoding = NULL;
+ if (args.Length() == 1 && args[0]->IsString())
+ {
+ encoding = new XML_Char[32];
+ args[0]->ToString()->WriteAscii(encoding, 0, 32);
+ }
+
+ int status = parser->reset(encoding);
+ if (status)
+ parser->attachHandlers();
+ return scope.Close(status ? True() : False());
+ }
+
+ int reset(XML_Char *encoding)
+ {
+ return XML_ParserReset(parser, encoding) != 0;
+ }
const XML_LChar *getError()
{
enum XML_Error code;
@@ -287,7 +314,7 @@ class Parser : public ObjectWrap {
/* no default ctor */
Parser();
-
+
/*** SAX callbacks ***/
/* Should a local HandleScope be used in those callbacks? */

0 comments on commit f638c46

Please sign in to comment.