File: kconv.rb

package info (click to toggle)
ruby 1.4.3-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,068 kB
  • ctags: 7,509
  • sloc: ansic: 60,668; ruby: 23,106; yacc: 4,122; sh: 1,753; lisp: 997; makefile: 597; sed: 68; awk: 36; tcl: 31; perl: 17; python: 6
file content (58 lines) | stat: -rw-r--r-- 907 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
require 'nkf'

module Kconv
  AUTO = NKF::AUTO
  JIS = NKF::JIS
  EUC = NKF::EUC
  SJIS = NKF::SJIS
  BINARY = NKF::BINARY
  NOCONV = NKF::NOCONV
  UNKNOWN = NKF::UNKNOWN
  def kconv(str, out_code, in_code = AUTO)
    opt = '-'
    case in_code
    when NKF::JIS
      opt << 'J'
    when NKF::EUC
      opt << 'E'
    when NKF::SJIS
      opt << 'S'
    end

    case out_code
    when NKF::JIS
      opt << 'j'
    when NKF::EUC
      opt << 'e'
    when NKF::SJIS
      opt << 's'
    when NKF::NOCONV
      return str
    end

    opt = '' if opt == '-'

    NKF::nkf(opt, str)
  end
  module_function :kconv

  def tojis(str)
    NKF::nkf('-j', str)
  end
  module_function :tojis

  def toeuc(str)
    NKF::nkf('-e', str)
  end
  module_function :toeuc

  def tosjis(str)
    NKF::nkf('-s', str)
  end
  module_function :tosjis

  def guess(str)
    NKF::guess(str)
  end
  module_function :guess
end