Sha256: 4d5e2ecd3c9915811d76383c6fc179b330497993dbad6dbb957a8d0cf6a8d124

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

#include <xml_syntax_error.h>

void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
{
  VALUE list = (VALUE)ctx;
  rb_ary_push(list,  Nokogiri_wrap_xml_syntax_error( Qnil , error));
}

void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
{
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error( Qnil , error));
}

VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
{
  VALUE msg, e;

  if( klass == Qnil ) klass = cNokogiriXmlSyntaxError;

  msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;

  e = rb_class_new_instance(
      1,
      &msg,
      klass
  );

  if (error)
  {
    rb_iv_set(e, "@domain", INT2NUM(error->domain));
    rb_iv_set(e, "@code", INT2NUM(error->code));
    rb_iv_set(e, "@level", INT2NUM((short)error->level));
    rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
    rb_iv_set(e, "@line", INT2NUM(error->line));
    rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
    rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
    rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
    rb_iv_set(e, "@int1", INT2NUM(error->int1));
    rb_iv_set(e, "@column", INT2NUM(error->int2));
  }

  return e;
}

VALUE cNokogiriXmlSyntaxError;
void init_xml_syntax_error()
{
  VALUE nokogiri = rb_define_module("Nokogiri");
  VALUE xml = rb_define_module_under(nokogiri, "XML");

  /*
   * The XML::SyntaxError is raised on parse errors
   */
  VALUE syntax_error_mommy = rb_define_class_under(nokogiri, "SyntaxError", rb_eStandardError);
  VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
  cNokogiriXmlSyntaxError = klass;

}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nokogiri-maglev--1.5.5.20120817130721 ext/nokogiri/xml_syntax_error.c
nokogiri-maglev--1.5.2 ext/nokogiri/xml_syntax_error.c
nokogiri-maglev--1.5.5 ext/nokogiri/xml_syntax_error.c
nokogiri-maglev--1.5.4.20120815005250 ext/nokogiri/xml_syntax_error.c
nokogiri-maglev--1.5.3 ext/nokogiri/xml_syntax_error.c
nokogiri-maglev--1.5.0.1 ext/nokogiri/xml_syntax_error.c