summaryrefslogtreecommitdiff
path: root/lib/rexml/encodings/Shift-JIS.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rexml/encodings/Shift-JIS.rb')
-rw-r--r--lib/rexml/encodings/Shift-JIS.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/rexml/encodings/Shift-JIS.rb b/lib/rexml/encodings/Shift-JIS.rb
index 8650174538..e805456ea7 100644
--- a/lib/rexml/encodings/Shift-JIS.rb
+++ b/lib/rexml/encodings/Shift-JIS.rb
@@ -3,15 +3,30 @@ begin
module REXML
module Encoding
- def to_shift_jis content
+ def from_shift_jis(str)
Uconv::u8tosjis(content)
end
- def from_shift_jis(str)
+ def to_shift_jis content
Uconv::sjistou8(str)
end
end
end
rescue LoadError
- raise "uconv is required for Japanese encoding support."
+ begin
+ require 'iconv'
+ module REXML
+ module Encoding
+ def from_shift_jis(str)
+ return Iconv::iconv("utf-8", "shift-jis", str)[0]
+ end
+
+ def to_shift_jis content
+ return Iconv::iconv("euc-jp", "shift-jis", content)[0]
+ end
+ end
+ end
+ rescue LoadError
+ raise "uconv or iconv is required for Japanese encoding support."
+ end
end