diff options
author | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
---|---|---|
committer | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
commit | ed512acb2fd71016e320414a16b3262ce2f9c366 (patch) | |
tree | 2e3a631d82871b691dc1a7c0633033fa04ff8d2f /lib/rexml/encodings/SHIFT-JIS.rb | |
parent | d4d497dd86962d333337b70392623ccde5a053c2 (diff) |
Cross-ported the REXML changes from HEAD to the 1.8 branch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/encodings/SHIFT-JIS.rb')
-rw-r--r-- | lib/rexml/encodings/SHIFT-JIS.rb | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/lib/rexml/encodings/SHIFT-JIS.rb b/lib/rexml/encodings/SHIFT-JIS.rb index f17c927864..cbbb88e683 100644 --- a/lib/rexml/encodings/SHIFT-JIS.rb +++ b/lib/rexml/encodings/SHIFT-JIS.rb @@ -1,37 +1,22 @@ -begin - require 'iconv' +require 'uconv' - module REXML - module Encoding - @@__REXML_encoding_methods =<<-EOL - def decode(str) - return Iconv::iconv("utf-8", "shift_jis", str)[0] - end - - def encode content - return Iconv::iconv("shift_jis", "utf-8", content)[0] - end - EOL +module REXML + module Encoding + def decode_sjis content + Uconv::u8tosjis(content) end - end -rescue LoadError - begin - require 'uconv' - module REXML - module Encoding - @@__REXML_encoding_methods =<<-EOL - def encode(content) - Uconv::u8tosjis(content) - end + def encode_sjis(str) + Uconv::sjistou8(str) + end - def decode(str) - Uconv::sjistou8(str) - end - EOL + b = proc do |obj| + class << obj + alias decode decode_sjis + alias encode encode_sjis end end - rescue LoadError - raise "uconv or iconv is required for Japanese encoding support." + register("SHIFT-JIS", &b) + register("SHIFT_JIS", &b) end end |