Module Kconv
In: ext/nkf/lib/kconv.rb

Kanji Converter for Ruby.

Methods

guess   guess_old   iseuc   issjis   isutf8   kconv   toeuc   tojis   tosjis   toutf16   toutf8  

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
REVISION = %q$Revision: 11708 $   Revision of kconv.rb
RegexpShiftjis = /\A(?: [\x00-\x7f\xa1-\xdf] | [\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc] )*\z/nx   Regexp of Shift_JIS string (private constant)
RegexpEucjp = /\A(?: [\x00-\x7f] | \x8e [\xa1-\xdf] | \x8f [\xa1-\xfe] [\xa1-\xfe] | [\xa1-\xfe] [\xa1-\xfe] )*\z/nx   Regexp of EUC-JP string (private constant)
RegexpUtf8 = /\A(?: [\x00-\x7f] | [\xc2-\xdf] [\x80-\xbf] | \xe0 [\xa0-\xbf] [\x80-\xbf] | [\xe1-\xef] [\x80-\xbf] [\x80-\xbf] | \xf0 [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] | [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] | \xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf] )*\z/nx   Regexp of UTF-8 string (private constant)

Public Instance methods

Guess input encoding by NKF.guess2

[Source]

     # File ext/nkf/lib/kconv.rb, line 213
213:   def guess(str)
214:     ::NKF::guess(str)
215:   end

Guess input encoding by NKF.guess1

[Source]

     # File ext/nkf/lib/kconv.rb, line 222
222:   def guess_old(str)
223:     ::NKF::guess1(str)
224:   end

Returns whether input encoding is EUC-JP or not.

Note don‘t expect this return value is MatchData.

[Source]

     # File ext/nkf/lib/kconv.rb, line 237
237:   def iseuc(str)
238:     RegexpEucjp.match( str )
239:   end

Returns whether input encoding is Shift_JIS or not.

Note don‘t expect this return value is MatchData.

[Source]

     # File ext/nkf/lib/kconv.rb, line 248
248:   def issjis(str)
249:     RegexpShiftjis.match( str )
250:   end

Returns whether input encoding is UTF-8 or not.

Note don‘t expect this return value is MatchData.

[Source]

     # File ext/nkf/lib/kconv.rb, line 259
259:   def isutf8(str)
260:     RegexpUtf8.match( str )
261:   end

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.

[Source]

     # File ext/nkf/lib/kconv.rb, line 95
 95:   def kconv(str, out_code, in_code = AUTO)
 96:     opt = '-'
 97:     case in_code
 98:     when ::NKF::JIS
 99:       opt << 'J'
100:     when ::NKF::EUC
101:       opt << 'E'
102:     when ::NKF::SJIS
103:       opt << 'S'
104:     when ::NKF::UTF8
105:       opt << 'W'
106:     when ::NKF::UTF16
107:       opt << 'W16'
108:     end
109: 
110:     case out_code
111:     when ::NKF::JIS
112:       opt << 'j'
113:     when ::NKF::EUC
114:       opt << 'e'
115:     when ::NKF::SJIS
116:       opt << 's'
117:     when ::NKF::UTF8
118:       opt << 'w'
119:     when ::NKF::UTF16
120:       opt << 'w16'
121:     when ::NKF::NOCONV
122:       return str
123:     end
124: 
125:     opt = '' if opt == '-'
126: 
127:     ::NKF::nkf(opt, str)
128:   end

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).

[Source]

     # File ext/nkf/lib/kconv.rb, line 158
158:   def toeuc(str)
159:     ::NKF::nkf('-em', str)
160:   end

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).

[Source]

     # File ext/nkf/lib/kconv.rb, line 144
144:   def tojis(str)
145:     ::NKF::nkf('-jm', str)
146:   end

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).

[Source]

     # File ext/nkf/lib/kconv.rb, line 172
172:   def tosjis(str)
173:     ::NKF::nkf('-sm', str)
174:   end

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).

[Source]

     # File ext/nkf/lib/kconv.rb, line 200
200:   def toutf16(str)
201:     ::NKF::nkf('-w16m', str)
202:   end

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).

[Source]

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

[Validate]