123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::EncodingHandler

Relationships & Source Files
Inherits: Object
Defined in: ext/nokogiri/xml_encoding_handler.c,
lib/nokogiri/encoding_handler.rb

Constant Summary

  • USEFUL_ALIASES =

    Popular encoding aliases not known by all iconv implementations that ::Nokogiri should support.

    # File 'lib/nokogiri/encoding_handler.rb', line 7
    {
      # alias_name => true_name
      "NOKOGIRI-SENTINEL" => "UTF-8", # indicating the Nokogiri has installed aliases
      "Windows-31J" => "CP932", # Windows-31J is the IANA registered name of CP932.
      "UTF-8" => "UTF-8", # for JRuby tests, this is a no-op in CRuby
    }

Class Method Summary

Instance Attribute Summary

  • #name readonly Internal use only

    Get the name of this EncodingHandler.

Constructor Details

.new(name) ⇒ EncodingHandler

This method is for internal use only.
[ GitHub ]

  
# File 'lib/nokogiri/encoding_handler.rb', line 48

def initialize(name)
  @name = name
end

Class Method Details

.[](name)

This method is for internal use only.
[ GitHub ]

  
# File 'ext/nokogiri/xml_encoding_handler.c', line 27

static VALUE
rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)
{
  xmlCharEncodingHandlerPtr handler;

  handler = xmlFindCharEncodingHandler(StringValueCStr(key));
  if (handler) {
    return TypedData_Wrap_Struct(klass, &xml_char_encoding_handler_type, handler);
  }

  return Qnil;
}

.alias(real_name, alias_name)

This method is for internal use only.

Alias encoding handler with name real_name to name alias_name

[ GitHub ]

  
# File 'ext/nokogiri/xml_encoding_handler.c', line 60

static VALUE
rb_xml_encoding_handler_s_alias(VALUE klass, VALUE from, VALUE to)
{
  xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));

  return to;
}

.clear_aliases!

This method is for internal use only.

Remove all encoding aliases.

[ GitHub ]

  
# File 'ext/nokogiri/xml_encoding_handler.c', line 74

static VALUE
rb_xml_encoding_handler_s_clear_aliases(VALUE klass)
{
  xmlCleanupEncodingAliases();

  return klass;
}

.delete(name)

This method is for internal use only.

Delete the encoding alias named #name

[ GitHub ]

  
# File 'ext/nokogiri/xml_encoding_handler.c', line 46

static VALUE
rb_xml_encoding_handler_s_delete(VALUE klass, VALUE name)
{
  if (xmlDelEncodingAlias(StringValueCStr(name))) { return Qnil; }

  return Qtrue;
}

.install_default_aliases

[ GitHub ]

  
# File 'lib/nokogiri/encoding_handler.rb', line 15

def install_default_aliases
  USEFUL_ALIASES.each do |alias_name, name|
    EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
  end
end

.storage (private)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/nokogiri/encoding_handler.rb', line 43

def storage
  @storage ||= {}
end

Instance Attribute Details

#name (readonly)

This method is for internal use only.

Get the name of this EncodingHandler

[ GitHub ]

  
# File 'ext/nokogiri/xml_encoding_handler.c', line 88

static VALUE
rb_xml_encoding_handler_name(VALUE self)
{
  xmlCharEncodingHandlerPtr handler;

  TypedData_Get_Struct(self, xmlCharEncodingHandler, &xml_char_encoding_handler_type, handler);

  return NOKOGIRI_STR_NEW2(handler->name);
}