In Files

  • nkf/lib/kconv.rb

Class/Module Index [+]

Quicksearch

Kconv

Kanji Converter for Ruby.

Constants

ASCII

ASCII

AUTO

Auto-Detect

BINARY

BINARY

EUC

EUC-JP

JIS

ISO-2022-JP

NOCONV

NOCONV

REVISION

Revision of kconv.rb

RegexpEucjp

Regexp of EUC-JP string (private constant)

RegexpShiftjis

Regexp of Shift_JIS string (private constant)

RegexpUtf8

Regexp of UTF-8 string (private constant)

SJIS

Shift_JIS

UNKNOWN

UNKNOWN

UTF16

UTF-16

UTF32

UTF-32

UTF8

UTF-8

Public Class Methods

guess(str) → integer click to toggle source

Guess input encoding by NKF.guess2

 
               # File nkf/lib/kconv.rb, line 213
def guess(str)
  ::NKF::guess(str)
end
            
guess_old(str) → integer click to toggle source

Guess input encoding by NKF.guess1

 
               # File nkf/lib/kconv.rb, line 222
def guess_old(str)
  ::NKF::guess1(str)
end
            
iseuc(str) → obj or nil click to toggle source

Returns whether input encoding is EUC-JP or not.

Note don't expect this return value is MatchData.

 
               # File nkf/lib/kconv.rb, line 237
def iseuc(str)
  RegexpEucjp.match( str )
end
            
issjis(str) → obj or nil click to toggle source

Returns whether input encoding is Shift_JIS or not.

Note don't expect this return value is MatchData.

 
               # File nkf/lib/kconv.rb, line 248
def issjis(str)
  RegexpShiftjis.match( str )
end
            
isutf8(str) → obj or nil click to toggle source

Returns whether input encoding is UTF-8 or not.

Note don't expect this return value is MatchData.

 
               # File nkf/lib/kconv.rb, line 259
def isutf8(str)
  RegexpUtf8.match( str )
end
            
kconv(str, out_code, in_code = Kconv::AUTO) click to toggle source

Convert str to out_code. out_code and in_code are given as constants of Kconv.

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want to decode them, use NKF.nkf.

 
               # File nkf/lib/kconv.rb, line 95
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'
  when ::NKF::UTF8
    opt << 'W'
  when ::NKF::UTF16
    opt << 'W16'
  end

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

  opt = '' if opt == '-'

  ::NKF::nkf(opt, str)
end
            
toeuc(str) → string click to toggle source

Convert str to EUC-JP

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want it, use NKF.nkf('-exm0', str).

 
               # File nkf/lib/kconv.rb, line 158
def toeuc(str)
  ::NKF::nkf('-em', str)
end
            
tojis(str) → string click to toggle source

Convert str to ISO-2022-JP

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want it, use NKF.nkf('-jxm0', str).

 
               # File nkf/lib/kconv.rb, line 144
def tojis(str)
  ::NKF::nkf('-jm', str)
end
            
tosjis(str) → string click to toggle source

Convert str to Shift_JIS

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want it, use NKF.nkf('-sxm0', str).

 
               # File nkf/lib/kconv.rb, line 172
def tosjis(str)
  ::NKF::nkf('-sm', str)
end
            
toutf16(str) → string click to toggle source

Convert str to UTF-16

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want it, use NKF.nkf('-w16xm0', str).

 
               # File nkf/lib/kconv.rb, line 200
def toutf16(str)
  ::NKF::nkf('-w16m', str)
end
            
toutf8(str) → string click to toggle source

Convert str to UTF-8

Note This method decode MIME encoded string and convert halfwidth katakana to fullwidth katakana. If you don't want it, use NKF.nkf('-wxm0', str).

 
               # File nkf/lib/kconv.rb, line 186
def toutf8(str)
  ::NKF::nkf('-wm', str)
end