File: xmlencoding-ja.rb

package info (click to toggle)
libxml-parser-ruby 0.6.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 676 kB
  • ctags: 800
  • sloc: ruby: 5,723; ansic: 1,734; xml: 574; makefile: 152
file content (47 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
## -*- Ruby -*-
## Sample XMLEncoding class for Japanese (EUC-JP, Shift_JIS)
## 1998 by yoshidam
##
## Usage:
##    require 'xmlencoding-ja'
##    include XMLEncoding_ja

module XMLEncoding_ja
  require 'xmlparser'
  require 'uconv'
  include Uconv
  require 'kconv'
  include Kconv

  class EUCHandler<XMLEncoding
    def map(i)
      return i if i < 128
      return -1 if i < 160 or i == 255
      return -2 
    end
    def convert(s)
      euctou2(s)
    end
  end

  class SJISHandler<XMLEncoding
    def map(i)
      return i if i < 128
      return -2 
    end
    def convert(s)
      euctou2(kconv(s, EUC, SJIS))
    end
  end

  def unknownEncoding(name)
    return EUCHandler.new if name =~ /^euc-jp$/i
    return SJISHandler.new if name =~ /^shift_jis$/i
    nil
  end

end

module XML
  Encoding_ja = XMLEncoding_ja
end