summaryrefslogtreecommitdiff
path: root/ruby_1_8_6/lib/rexml/encodings/EUC-JP.rb
blob: db37b6bf0d26e0b289cd080df94f697a27f85cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module REXML
  module Encoding
    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 decode_eucjp(str)
        NKF.nkf(EUCTOU8, str)
      end

      def encode_eucjp content
        NKF.nkf(U8TOEUC, content)
      end
    end

    register("EUC-JP") do |obj|
      class << obj
        alias decode decode_eucjp
        alias encode encode_eucjp
      end
    end
  end
end