2005-04-09 13:03:32 -04:00
|
|
|
module REXML
|
|
|
|
module Encoding
|
2005-12-09 09:31:47 -05:00
|
|
|
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'
|
2003-12-12 16:17:41 -05:00
|
|
|
|
2005-12-09 09:31:47 -05:00
|
|
|
def decode_sjis(str)
|
|
|
|
NKF.nkf(SJISTOU8, str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def encode_sjis content
|
|
|
|
NKF.nkf(U8TOSJIS, content)
|
|
|
|
end
|
2005-04-09 13:03:32 -04:00
|
|
|
end
|
2003-12-12 16:17:41 -05:00
|
|
|
|
2005-04-09 13:03:32 -04:00
|
|
|
b = proc do |obj|
|
|
|
|
class << obj
|
|
|
|
alias decode decode_sjis
|
|
|
|
alias encode encode_sjis
|
2003-12-12 16:17:41 -05:00
|
|
|
end
|
|
|
|
end
|
2005-04-09 13:03:32 -04:00
|
|
|
register("SHIFT-JIS", &b)
|
|
|
|
register("SHIFT_JIS", &b)
|
2003-12-12 16:17:41 -05:00
|
|
|
end
|
|
|
|
end
|