Class Encoding
In: transcode.c
encoding.c
Parent: Object

call-seq:

  Encoding.aliases => {"alias1" => "orig1", "alias2" => "orig2", ...}

Returns the hash of available encoding alias and original encoding name.

  Encoding.aliases
  => {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
      "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}

Methods

Classes and Modules

Class Encoding::Converter
Class Encoding::ConverterNotFoundError
Class Encoding::InvalidByteSequenceError
Class Encoding::UndefinedConversionError

Public Class methods

Returns the hash of available encoding alias and original encoding name.

  Encoding.aliases
  => {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
      "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}

Checks the compatibility of two strings. If they are compatible, means concatenatable, returns an encoding which the concatinated string will be. If they are not compatible, nil is returned.

  Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
  => #<Encoding:ISO-8859-1>

  Encoding.compatible?(
    "\xa1".force_encoding("iso-8859-1"),
    "\xa1\xa1".force_encoding("euc-jp"))
  => nil

Returns default external encoding.

It is initialized by the locale or -E option.

Sets default external encoding.

Returns default internal encoding.

It is initialized by the source internal_encoding or -E option.

Sets default internal encoding. Or removes default internal encoding when passed nil.

Search the encoding with specified name. name should be a string or symbol.

  Encoding.find("US-ASCII")  => #<Encoding:US-ASCII>
  Encoding.find(:Shift_JIS)  => #<Encoding:Shift_JIS>

An ArgumentError is raised when no encoding with name. Only +Encoding.find("internal")+ however returns nil when no encoding named "internal", in other words, when Ruby has no default internal encoding.

Returns the list of loaded encodings.

  Encoding.list
  => [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
      #<Encoding:ISO-2022-JP (dummy)>]

  Encoding.find("US-ASCII")
  => #<Encoding:US-ASCII>

  Encoding.list
  => [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
      #<Encoding:US-ASCII>, #<Encoding:ISO-2022-JP (dummy)>]

Returns the locale charmap name.

  Debian GNU/Linux
    LANG=C
      Encoding.locale_charmap  => "ANSI_X3.4-1968"
    LANG=ja_JP.EUC-JP
      Encoding.locale_charmap  => "EUC-JP"

  SunOS 5
    LANG=C
      Encoding.locale_charmap  => "646"
    LANG=ja
      Encoding.locale_charmap  => "eucJP"

The result is higly platform dependent. So Encoding.find(Encoding.locale_charmap) may cause an error. If you need some encoding object even for unknown locale, Encoding.find("locale") can be used.

Returns the list of available encoding names.

  Encoding.name_list
  => ["US-ASCII", "ASCII-8BIT", "UTF-8",
      "ISO-8859-1", "Shift_JIS", "EUC-JP",
      "Windows-31J",
      "BINARY", "CP932", "eucJP"]

Public Instance methods

Returns true for dummy encodings. A dummy encoding is an encoding for which character handling is not properly implemented. It is used for stateful encodings.

  Encoding::ISO_2022_JP.dummy?       #=> true
  Encoding::UTF_8.dummy?             #=> false

Returns a string which represents the encoding for programmers.

  Encoding::UTF_8.inspect       #=> "#<Encoding:UTF-8>"
  Encoding::ISO_2022_JP.inspect #=> "#<Encoding:ISO-2022-JP (dummy)>"

Returns the name of the encoding.

  Encoding::UTF_8.name       => "UTF-8"

Returns the list of name and aliases of the encoding.

  Encoding::WINDOWS_31J.names => ["Windows-31J", "CP932", "csWindows31J"]

Returns the name of the encoding.

  Encoding::UTF_8.name       => "UTF-8"

[Validate]