/*
* call-seq:
* read_memory(string, url, encoding, options)
*
* Create a new document from a String
*/
static VALUE read_memory( VALUE klass,
VALUE string,
VALUE url,
VALUE encoding,
VALUE options )
{
const char * c_buffer = StringValuePtr(string);
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0));
xmlInitParser();
xmlDocPtr doc = xmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
if(doc == NULL) {
xmlFreeDoc(doc);
rb_raise(rb_eRuntimeError, "Couldn't create a document");
return Qnil;
}
return Nokogiri_wrap_xml_document(klass, doc);
}