diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-01 05:43:50 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-01 05:43:50 +0000 |
commit | 1448668244c81cfc720bcdfa93af352a17cc230f (patch) | |
tree | 550af4707b22d099f4d8393e29ef6da424aca813 /lib/rexml/source.rb | |
parent | 96e7713754c477fe98806b905301356371accb68 (diff) |
* lib/rexml: 1.9 patch from Sam Ruby mentioned in his blog:
<http://intertwingly.net/blog/2007/12/31/Porting-REXML-to-Ruby-1-9>
[ruby-core:14639]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/source.rb')
-rw-r--r-- | lib/rexml/source.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index e05460fea1..3f14239a35 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -59,6 +59,9 @@ module REXML @to_utf = true else @to_utf = false + if @buffer.respond_to? :force_encoding + @buffer.force_encoding Encoding::UTF_8 + end end end @@ -147,13 +150,13 @@ module REXML str = @source.read( 2 ) if encoding self.encoding = encoding - elsif 0xfe == str[0] && 0xff == str[1] + elsif str[0,2] == "\xfe\xff" @line_break = "\000>" - elsif 0xff == str[0] && 0xfe == str[1] + elsif str[0,2] == "\xff\xfe" @line_break = ">\000" - elsif 0xef == str[0] && 0xbb == str[1] + elsif str[0,2] == "\xef\xbb" str += @source.read(1) - str = '' if (0xbf == str[2]) + str = '' if (str[2,1] == "\xBF") @line_break = ">" else @line_break = ">" @@ -193,6 +196,9 @@ module REXML str = @source.readline(@line_break) str = decode(str) if @to_utf and str @buffer << str + if not @to_utf and @buffer.respond_to? :force_encoding + @buffer.force_encoding Encoding::UTF_8 + end rescue Exception, NameError @source = nil end |