Kanji Converter for Ruby.

Methods
G
I
K
T
Constants
AUTO = NKF::AUTO
 

Auto-Detect

JIS = NKF::JIS
 

ISO-2022-JP

EUC = NKF::EUC
 

EUC-JP

SJIS = NKF::SJIS
 

Shift_JIS

BINARY = NKF::BINARY
 

BINARY

NOCONV = NKF::NOCONV
 

NOCONV

ASCII = NKF::ASCII
 

ASCII

UTF8 = NKF::UTF8
 

UTF-8

UTF16 = NKF::UTF16
 

UTF-16

UTF32 = NKF::UTF32
 

UTF-32

UNKNOWN = NKF::UNKNOWN
 

UNKNOWN

Class Public methods
Kconv.guess(str) => encoding

Guess input encoding by NKF.guess

     # File ext/nkf/lib/kconv.rb, line 140
140:   def guess(str)
141:     ::NKF::guess(str)
142:   end
Kconv.iseuc(str) => true or false

Returns whether input encoding is EUC-JP or not.

Note don’t expect this return value is MatchData.

     # File ext/nkf/lib/kconv.rb, line 155
155:   def iseuc(str)
156:     str.dup.force_encoding(EUC).valid_encoding?
157:   end
Kconv.isjis(str) => true or false

Returns whether input encoding is ISO-2022-JP or not.

     # File ext/nkf/lib/kconv.rb, line 173
173:   def isjis(str)
174:     /\A [\t\n\r\x20-\x7E]*
175:       (?:
176:         (?:\x1b \x28 I      [\x21-\x7E]*
177:           |\x1b \x28 J      [\x21-\x7E]*
178:           |\x1b \x24 @      (?:[\x21-\x7E]{2})*
179:           |\x1b \x24 B      (?:[\x21-\x7E]{2})*
180:           |\x1b \x24 \x28 D (?:[\x21-\x7E]{2})*
181:         )*
182:         \x1b \x28 B [\t\n\r\x20-\x7E]*
183:       )*
184:      \z/nox =~ str.dup.force_encoding('BINARY') ? true : false
185:   end
Kconv.issjis(str) => true or false

Returns whether input encoding is Shift_JIS or not.

     # File ext/nkf/lib/kconv.rb, line 164
164:   def issjis(str)
165:     str.dup.force_encoding(SJIS).valid_encoding?
166:   end
Kconv.isutf8(str) => true or false

Returns whether input encoding is UTF-8 or not.

     # File ext/nkf/lib/kconv.rb, line 192
192:   def isutf8(str)
193:     str.dup.force_encoding(UTF8).valid_encoding?
194:   end
Kconv.kconv(str, to_enc, from_enc=nil)

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

    # File ext/nkf/lib/kconv.rb, line 56
56:   def kconv(str, to_enc, from_enc=nil)
57:     opt = ''
58:     opt += ' --ic=' + from_enc.to_s if from_enc
59:     opt += ' --oc=' + to_enc.to_s if to_enc
60: 
61:     ::NKF::nkf(opt, str)
62:   end
Kconv.toeuc(str) => string

Convert str to EUC-JP

    # File ext/nkf/lib/kconv.rb, line 82
82:   def toeuc(str)
83:     kconv(str, EUC)
84:   end
Kconv.tojis(str) => string

Convert str to ISO-2022-JP

    # File ext/nkf/lib/kconv.rb, line 73
73:   def tojis(str)
74:     kconv(str, JIS)
75:   end
Kconv.tolocale => string

Convert self to locale encoding

     # File ext/nkf/lib/kconv.rb, line 127
127:   def tolocale(str)
128:     kconv(str, Encoding.locale_charmap)
129:   end
Kconv.tosjis(str) => string

Convert str to Shift_JIS

    # File ext/nkf/lib/kconv.rb, line 91
91:   def tosjis(str)
92:     kconv(str, SJIS)
93:   end
Kconv.toutf16(str) => string

Convert str to UTF-16

     # File ext/nkf/lib/kconv.rb, line 109
109:   def toutf16(str)
110:     kconv(str, UTF16)
111:   end
Kconv.toutf32(str) => string

Convert str to UTF-32

     # File ext/nkf/lib/kconv.rb, line 118
118:   def toutf32(str)
119:     kconv(str, UTF32)
120:   end
Kconv.toutf8(str) => string

Convert str to UTF-8

     # File ext/nkf/lib/kconv.rb, line 100
100:   def toutf8(str)
101:     kconv(str, UTF8)
102:   end
Instance Private methods
Kconv.guess(str) => encoding

Guess input encoding by NKF.guess

     # File ext/nkf/lib/kconv.rb, line 140
140:   def guess(str)
141:     ::NKF::guess(str)
142:   end
Kconv.iseuc(str) => true or false

Returns whether input encoding is EUC-JP or not.

Note don’t expect this return value is MatchData.

     # File ext/nkf/lib/kconv.rb, line 155
155:   def iseuc(str)
156:     str.dup.force_encoding(EUC).valid_encoding?
157:   end
Kconv.isjis(str) => true or false

Returns whether input encoding is ISO-2022-JP or not.

     # File ext/nkf/lib/kconv.rb, line 173
173:   def isjis(str)
174:     /\A [\t\n\r\x20-\x7E]*
175:       (?:
176:         (?:\x1b \x28 I      [\x21-\x7E]*
177:           |\x1b \x28 J      [\x21-\x7E]*
178:           |\x1b \x24 @      (?:[\x21-\x7E]{2})*
179:           |\x1b \x24 B      (?:[\x21-\x7E]{2})*
180:           |\x1b \x24 \x28 D (?:[\x21-\x7E]{2})*
181:         )*
182:         \x1b \x28 B [\t\n\r\x20-\x7E]*
183:       )*
184:      \z/nox =~ str.dup.force_encoding('BINARY') ? true : false
185:   end
Kconv.issjis(str) => true or false

Returns whether input encoding is Shift_JIS or not.

     # File ext/nkf/lib/kconv.rb, line 164
164:   def issjis(str)
165:     str.dup.force_encoding(SJIS).valid_encoding?
166:   end
Kconv.isutf8(str) => true or false

Returns whether input encoding is UTF-8 or not.

     # File ext/nkf/lib/kconv.rb, line 192
192:   def isutf8(str)
193:     str.dup.force_encoding(UTF8).valid_encoding?
194:   end
Kconv.kconv(str, to_enc, from_enc=nil)

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

    # File ext/nkf/lib/kconv.rb, line 56
56:   def kconv(str, to_enc, from_enc=nil)
57:     opt = ''
58:     opt += ' --ic=' + from_enc.to_s if from_enc
59:     opt += ' --oc=' + to_enc.to_s if to_enc
60: 
61:     ::NKF::nkf(opt, str)
62:   end
Kconv.toeuc(str) => string

Convert str to EUC-JP

    # File ext/nkf/lib/kconv.rb, line 82
82:   def toeuc(str)
83:     kconv(str, EUC)
84:   end
Kconv.tojis(str) => string

Convert str to ISO-2022-JP

    # File ext/nkf/lib/kconv.rb, line 73
73:   def tojis(str)
74:     kconv(str, JIS)
75:   end
Kconv.tolocale => string

Convert self to locale encoding

     # File ext/nkf/lib/kconv.rb, line 127
127:   def tolocale(str)
128:     kconv(str, Encoding.locale_charmap)
129:   end
Kconv.tosjis(str) => string

Convert str to Shift_JIS

    # File ext/nkf/lib/kconv.rb, line 91
91:   def tosjis(str)
92:     kconv(str, SJIS)
93:   end
Kconv.toutf16(str) => string

Convert str to UTF-16

     # File ext/nkf/lib/kconv.rb, line 109
109:   def toutf16(str)
110:     kconv(str, UTF16)
111:   end
Kconv.toutf32(str) => string

Convert str to UTF-32

     # File ext/nkf/lib/kconv.rb, line 118
118:   def toutf32(str)
119:     kconv(str, UTF32)
120:   end
Kconv.toutf8(str) => string

Convert str to UTF-8

     # File ext/nkf/lib/kconv.rb, line 100
100:   def toutf8(str)
101:     kconv(str, UTF8)
102:   end