diff options
Diffstat (limited to 'lib/rexml/encodings/SHIFT-JIS.rb')
-rw-r--r-- | lib/rexml/encodings/SHIFT-JIS.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/rexml/encodings/SHIFT-JIS.rb b/lib/rexml/encodings/SHIFT-JIS.rb index d055d0c761..93c7877afd 100644 --- a/lib/rexml/encodings/SHIFT-JIS.rb +++ b/lib/rexml/encodings/SHIFT-JIS.rb @@ -1,13 +1,28 @@ -require 'uconv' - module REXML module Encoding - def decode_sjis content - Uconv::sjistou8(content) - end + begin + require 'uconv' + + def decode_sjis content + Uconv::sjistou8(content) + end + + def encode_sjis(str) + Uconv::u8tosjis(str) + end + rescue LoadError + require 'nkf' + + SJISTOU8 = '-Swm0' + U8TOSJIS = '-Wsm0' - def encode_sjis(str) - Uconv::u8tosjis(str) + def decode_sjis(str) + NKF.nkf(SJISTOU8, str) + end + + def encode_sjis content + NKF.nkf(U8TOSJIS, content) + end end b = proc do |obj| |