/*
* call-seq:
* initialize_native(xml_sax, filename)
*
* Initialize the push parser with +xml_sax+ using +filename+
*/
static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
VALUE encoding)
{
htmlSAXHandlerPtr sax;
const char * filename = NULL;
htmlParserCtxtPtr ctx;
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
if(_filename != Qnil) filename = StringValuePtr(_filename);
if (!NIL_P(encoding)) {
enc = xmlParseCharEncoding(StringValuePtr(encoding));
if (enc == XML_CHAR_ENCODING_ERROR)
rb_raise(rb_eArgError, "Unsupported Encoding");
}
ctx = htmlCreatePushParserCtxt(
sax,
NULL,
NULL,
0,
filename,
enc
);
if(ctx == NULL)
rb_raise(rb_eRuntimeError, "Could not create a parser context");
ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);
ctx->sax2 = 1;
DATA_PTR(self) = ctx;
return self;
}