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: Move encoding detection code to base class.

* lib/rexml/encoding.rb: Remove needless encoding detection code.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2012-10-28 14:52:21 +00:00
parent 7ba54654a5
commit 718813ca9b
3 changed files with 61 additions and 58 deletions

View file

@ -20,19 +20,6 @@ module REXML
true
end
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
def encode(string)
string.encode(@encoding)
end