Sha256: 0cd291c2ddfe21412e9100caacd71e585b260e72d723e2ad4229b318bb9b3e87

Contents?: true

Size: 1.66 KB

Versions: 54

Compression:

Stored size: 1.66 KB

Contents

#include <nokogiri.h>

/*
 * call-seq: Nokogiri::EncodingHandler.[](name)
 *
 * Get the encoding handler for +name+
 */
static VALUE
get(VALUE klass, VALUE key)
{
  xmlCharEncodingHandlerPtr handler;

  handler = xmlFindCharEncodingHandler(StringValueCStr(key));
  if (handler) {
    return Data_Wrap_Struct(klass, NULL, NULL, handler);
  }

  return Qnil;
}

/*
 * call-seq: Nokogiri::EncodingHandler.delete(name)
 *
 * Delete the encoding alias named +name+
 */
static VALUE
delete (VALUE klass, VALUE name)
{
  if (xmlDelEncodingAlias(StringValueCStr(name))) { return Qnil; }

  return Qtrue;
}

/*
 * call-seq: Nokogiri::EncodingHandler.alias(from, to)
 *
 * Alias encoding handler with name +from+ to name +to+
 */
static VALUE
alias(VALUE klass, VALUE from, VALUE to)
{
  xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));

  return to;
}

/*
 * call-seq: Nokogiri::EncodingHandler.clear_aliases!
 *
 * Remove all encoding aliases.
 */
static VALUE
clear_aliases(VALUE klass)
{
  xmlCleanupEncodingAliases();

  return klass;
}

/*
 * call-seq: name
 *
 * Get the name of this EncodingHandler
 */
static VALUE
name(VALUE self)
{
  xmlCharEncodingHandlerPtr handler;

  Data_Get_Struct(self, xmlCharEncodingHandler, handler);

  return NOKOGIRI_STR_NEW2(handler->name);
}

void
noko_init_xml_encoding_handler()
{
  VALUE klass = rb_define_class_under(mNokogiri, "EncodingHandler", rb_cObject);

  rb_define_singleton_method(klass, "[]", get, 1);
  rb_define_singleton_method(klass, "delete", delete, 1);
  rb_define_singleton_method(klass, "alias", alias, 2);
  rb_define_singleton_method(klass, "clear_aliases!", clear_aliases, 0);
  rb_define_method(klass, "name", name, 0);
}

Version data entries

54 entries across 52 versions & 3 rubygems

Version Path
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.6-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.6-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.11.7-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7 ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-x86_64-linux ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-x86_64-darwin ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-x86-mingw32 ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-x86-linux ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-x64-mingw32 ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-java ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.7-arm64-darwin ext/nokogiri/xml_encoding_handler.c
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.3-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.11.6-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.6-x86_64-linux/ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6 ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6-x86_64-linux ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6-x86_64-darwin ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6-x86-mingw32 ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6-x86-linux ext/nokogiri/xml_encoding_handler.c
nokogiri-1.11.6-x64-mingw32 ext/nokogiri/xml_encoding_handler.c