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/
  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