Module: REXML::Encoding
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rexml/encoding.rb |
Instance Attribute Summary
-
#encoding
rw
ID —>
Encoding
name. - #encoding=(encoding) rw
Instance Method Summary
Instance Attribute Details
#encoding (rw)
ID —> Encoding
name
# File 'lib/rexml/encoding.rb', line 5
attr_reader :encoding
#encoding=(encoding) (rw)
[ GitHub ]# File 'lib/rexml/encoding.rb', line 6
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
Instance Method Details
#decode(string)
[ GitHub ]# File 'lib/rexml/encoding.rb', line 28
def decode(string) string.encode(::Encoding::UTF_8, @encoding) end
#encode(string)
[ GitHub ]# File 'lib/rexml/encoding.rb', line 24
def encode(string) string.encode(@encoding) end
#find_encoding(name) (private)
[ GitHub ]# File 'lib/rexml/encoding.rb', line 33
def find_encoding(name) case name when /\Ashift-jis\z/i return "SHIFT_JIS" when /\ACP-(\d+)\z/ name = "CP#{$1}" when /\AUTF-8\z/i return name end begin ::Encoding::Converter.search_convpath(name, 'UTF-8') rescue ::Encoding::ConverterNotFoundError return nil end name end