Sha256: 0d0a86adf8b31ce382b94cf8e4a27ff537ac1d05968cb3daf8c170bc2eceb41d

Contents?: true

Size: 1.29 KB

Versions: 276

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Nokogiri
  class EncodingHandler
    # Popular encoding aliases not known by all iconv implementations that Nokogiri should support.
    USEFUL_ALIASES = {
      # 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 << self
      def install_default_aliases
        USEFUL_ALIASES.each do |alias_name, name|
          EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
        end
      end
    end

    # :stopdoc:
    if Nokogiri.jruby?
      class << self
        def [](name)
          storage.key?(name) ? new(storage[name]) : nil
        end

        def alias(name, alias_name)
          storage[alias_name] = name
        end

        def delete(name)
          storage.delete(name)
        end

        def clear_aliases!
          storage.clear
        end

        private

        def storage
          @storage ||= {}
        end
      end

      def initialize(name)
        @name = name
      end

      attr_reader :name
    end
  end
end

Nokogiri::EncodingHandler.install_default_aliases

Version data entries

276 entries across 276 versions & 10 rubygems

Version Path
nokogiri-1.16.8 lib/nokogiri/encoding_handler.rb
nokogiri-1.16.8-arm-linux lib/nokogiri/encoding_handler.rb
nokogiri-1.16.8-arm64-darwin lib/nokogiri/encoding_handler.rb
nokogiri-1.16.8-aarch64-linux lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7 lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x86_64-linux lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x86_64-darwin lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x86-mingw32 lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x86-linux lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x64-mingw32 lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-x64-mingw-ucrt lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-java lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-arm64-darwin lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-arm-linux lib/nokogiri/encoding_handler.rb
nokogiri-1.16.7-aarch64-linux lib/nokogiri/encoding_handler.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/nokogiri-1.16.6-arm64-darwin/lib/nokogiri/encoding_handler.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/encoding_handler.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/encoding_handler.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/encoding_handler.rb
nokogiri-1.16.6 lib/nokogiri/encoding_handler.rb