summaryrefslogtreecommitdiff
path: root/lib/rexml/encodings
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-09 14:31:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-09 14:31:47 +0000
commitc9e950b7b88f9103827388f90f30b4ac12faf2a0 (patch)
tree63e3d08f113207c4a6dd623befa2a03236f98e9f /lib/rexml/encodings
parentd0e78ab05dbe5d3015274626fcfb8fee136c8ade (diff)
* lib/rexml/encoding.rb (encoding=): give priority to particular
conversion to iconv. [ruby-core:06520] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/encodings')
-rw-r--r--lib/rexml/encodings/EUC-JP.rb29
-rw-r--r--lib/rexml/encodings/SHIFT-JIS.rb29
-rw-r--r--lib/rexml/encodings/SHIFT_JIS.rb2
3 files changed, 45 insertions, 15 deletions
diff --git a/lib/rexml/encodings/EUC-JP.rb b/lib/rexml/encodings/EUC-JP.rb
index 684df0bbd6..db37b6bf0d 100644
--- a/lib/rexml/encodings/EUC-JP.rb
+++ b/lib/rexml/encodings/EUC-JP.rb
@@ -1,13 +1,28 @@
-require 'uconv'
-
module REXML
module Encoding
- def decode_eucjp(str)
- Uconv::euctou8(str)
- end
+ begin
+ require 'uconv'
+
+ def decode_eucjp(str)
+ Uconv::euctou8(str)
+ end
+
+ def encode_eucjp content
+ Uconv::u8toeuc(content)
+ end
+ rescue LoadError
+ require 'nkf'
+
+ EUCTOU8 = '-Ewm0'
+ U8TOEUC = '-Wem0'
- def encode_eucjp content
- Uconv::u8toeuc(content)
+ def decode_eucjp(str)
+ NKF.nkf(EUCTOU8, str)
+ end
+
+ def encode_eucjp content
+ NKF.nkf(U8TOEUC, content)
+ end
end
register("EUC-JP") do |obj|
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|
diff --git a/lib/rexml/encodings/SHIFT_JIS.rb b/lib/rexml/encodings/SHIFT_JIS.rb
index 2fc0b28306..e355704a7c 100644
--- a/lib/rexml/encodings/SHIFT_JIS.rb
+++ b/lib/rexml/encodings/SHIFT_JIS.rb
@@ -1 +1 @@
-load 'rexml/encodings/SHIFT-JIS.rb'
+require 'rexml/encodings/SHIFT-JIS'