1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rexml/source.rb (REXML::Source::encoding): should not

convert the body twice.  [ruby-core:08828]

* lib/rexml/encoding.rb (REXML::Encoding::encoding):
  Encoding#encoding= to return boolean value to tell if the body
  is really converted or not.

* lib/rexml/encoding.rb (REXML::Encoding::encoding): Specific
  conversion library (e.g. rexml/encodings/UTF-16.rb) to have
  higher preceding.

* lib/rexml/encodings/UTF-16.rb (REXML::Encoding::decode_utf16):
  UTF-16#decode_utf16 should work strings without BOM.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-09-11 02:48:17 +00:00
parent 390b340d52
commit f2ad09d5b7
4 changed files with 35 additions and 16 deletions

View file

@ -1,3 +1,19 @@
Mon Sep 11 11:42:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rexml/source.rb (REXML::Source::encoding): should not
convert the body twice. [ruby-core:08828]
* lib/rexml/encoding.rb (REXML::Encoding::encoding):
Encoding#encoding= to return boolean value to tell if the body
is really converted or not.
* lib/rexml/encoding.rb (REXML::Encoding::encoding): Specific
conversion library (e.g. rexml/encodings/UTF-16.rb) to have
higher preceding.
* lib/rexml/encodings/UTF-16.rb (REXML::Encoding::decode_utf16):
UTF-16#decode_utf16 should work strings without BOM.
Mon Sep 11 07:39:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Sep 11 07:39:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (sym_equal): "sym == str" should compare them as * string.c (sym_equal): "sym == str" should compare them as

View file

@ -24,21 +24,22 @@ module REXML
old_verbosity = $VERBOSE old_verbosity = $VERBOSE
begin begin
$VERBOSE = false $VERBOSE = false
return if defined? @encoding and enc == @encoding enc = enc.nil? ? nil : enc.upcase
return false if defined? @encoding and enc == @encoding
if enc and enc != UTF_8 if enc and enc != UTF_8
@encoding = enc.upcase @encoding = enc
begin raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
require 'rexml/encodings/ICONV.rb' @encoding.untaint
Encoding.apply(self, "ICONV") enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
rescue LoadError, Exception => err begin
raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/ require enc_file
@encoding.untaint Encoding.apply(self, @encoding)
enc_file = File.join( "rexml", "encodings", "#@encoding.rb" ) rescue LoadError, Exception
begin begin
require enc_file require 'rexml/encodings/ICONV.rb'
Encoding.apply(self, @encoding) Encoding.apply(self, "ICONV")
rescue LoadError rescue LoadError => err
puts $!.message puts err.message
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv." raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
end end
end end
@ -50,6 +51,7 @@ module REXML
ensure ensure
$VERBOSE = old_verbosity $VERBOSE = old_verbosity
end end
true
end end
def check_encoding str def check_encoding str

View file

@ -16,9 +16,10 @@ module REXML
end end
def decode_utf16(str) def decode_utf16(str)
str = str[2..-1] if /^\376\377/ =~ str
array_enc=str.unpack('C*') array_enc=str.unpack('C*')
array_utf8 = [] array_utf8 = []
2.step(array_enc.size-1, 2){|i| 0.step(array_enc.size-1, 2){|i|
array_utf8 << (array_enc.at(i+1) + array_enc.at(i)*0x100) array_utf8 << (array_enc.at(i+1) + array_enc.at(i)*0x100)
} }
array_utf8.pack('U*') array_utf8.pack('U*')

View file

@ -44,7 +44,7 @@ module REXML
# Inherited from Encoding # Inherited from Encoding
# Overridden to support optimized en/decoding # Overridden to support optimized en/decoding
def encoding=(enc) def encoding=(enc)
super return unless super
@line_break = encode( '>' ) @line_break = encode( '>' )
if enc != UTF_8 if enc != UTF_8
@buffer = decode(@buffer) @buffer = decode(@buffer)