Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • rexml/encoding.rb
  • rexml/parsers/baseparser.rb
  • rexml/source.rb

Class/Module Index [+]

Quicksearch

REXML::Encoding

Attributes

encoding[R]

ID —> Encoding name

Public Instance Methods

check_encoding(xml) click to toggle source
 
               # File rexml/encoding.rb, line 23
def check_encoding(xml)
  # We have to recognize UTF-16BE, UTF-16LE, and UTF-8
  if xml[0, 2] == "\xfe\xff"
    xml[0, 2] = ""
    return 'UTF-16BE'
  elsif xml[0, 2] == "\xff\xfe"
    xml[0, 2] = ""
    return 'UTF-16LE'
  end
  xml =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/m
  return $3 ? $3.upcase : 'UTF-8'
end
            
decode(string) click to toggle source
 
               # File rexml/encoding.rb, line 40
def decode(string)
  string.encode(::Encoding::UTF_8, @encoding)
end
            
encode(string) click to toggle source
 
               # File rexml/encoding.rb, line 36
def encode(string)
  string.encode(@encoding)
end
            
encoding=(encoding) click to toggle source
 
               # File rexml/encoding.rb, line 5
def encoding=(encoding)
  encoding = encoding.name if encoding.is_a?(Encoding)
  if encoding.is_a?(String)
    original_encoding = encoding
    encoding = find_encoding(encoding)
    unless encoding
      raise ArgumentError, "Bad encoding name #{original_encoding}"
    end
  end
  return false if defined?(@encoding) and encoding == @encoding
  if encoding
    @encoding = encoding.upcase
  else
    @encoding = 'UTF-8'
  end
  true
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.