Kanji Converter for Ruby.
- G
- I
- K
- T
| AUTO | = | NKF::AUTO |
Auto-Detect |
||
| JIS | = | NKF::JIS |
ISO-2022-JP |
||
| EUC | = | NKF::EUC |
EUC-JP |
||
| SJIS | = | NKF::SJIS |
Shift_JIS |
||
| BINARY | = | NKF::BINARY |
| NOCONV | = | NKF::NOCONV |
| ASCII | = | NKF::ASCII |
| UTF8 | = | NKF::UTF8 |
UTF-8 |
||
| UTF16 | = | NKF::UTF16 |
UTF-16 |
||
| UTF32 | = | NKF::UTF32 |
UTF-32 |
||
| UNKNOWN | = | NKF::UNKNOWN |
Guess input encoding by NKF.guess
Source: show
# File ext/nkf/lib/kconv.rb, line 140 140: def guess(str) 141: ::NKF::guess(str) 142: end
Returns whether input encoding is EUC-JP or not.
Note don’t expect this return value is MatchData.
Source: show
# File ext/nkf/lib/kconv.rb, line 155 155: def iseuc(str) 156: str.dup.force_encoding(EUC).valid_encoding? 157: end
Returns whether input encoding is ISO-2022-JP or not.
Source: show
# 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
Returns whether input encoding is Shift_JIS or not.
Source: show
# File ext/nkf/lib/kconv.rb, line 164 164: def issjis(str) 165: str.dup.force_encoding(SJIS).valid_encoding? 166: end
Returns whether input encoding is UTF-8 or not.
Source: show
# File ext/nkf/lib/kconv.rb, line 192 192: def isutf8(str) 193: str.dup.force_encoding(UTF8).valid_encoding? 194: end
Convert str to out_code. out_code and in_code are given as constants of Kconv.
Source: show
# 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
Convert str to EUC-JP
Source: show
# File ext/nkf/lib/kconv.rb, line 82 82: def toeuc(str) 83: kconv(str, EUC) 84: end
Convert str to ISO-2022-JP
Source: show
# File ext/nkf/lib/kconv.rb, line 73 73: def tojis(str) 74: kconv(str, JIS) 75: end
Convert self to locale encoding
Source: show
# File ext/nkf/lib/kconv.rb, line 127 127: def tolocale(str) 128: kconv(str, Encoding.locale_charmap) 129: end
Convert str to Shift_JIS
Source: show
# File ext/nkf/lib/kconv.rb, line 91 91: def tosjis(str) 92: kconv(str, SJIS) 93: end
Convert str to UTF-16
Source: show
# File ext/nkf/lib/kconv.rb, line 109 109: def toutf16(str) 110: kconv(str, UTF16) 111: end
Convert str to UTF-32
Source: show
# File ext/nkf/lib/kconv.rb, line 118 118: def toutf32(str) 119: kconv(str, UTF32) 120: end
Convert str to UTF-8
Source: show
# File ext/nkf/lib/kconv.rb, line 100 100: def toutf8(str) 101: kconv(str, UTF8) 102: end
Guess input encoding by NKF.guess
Source: show
# File ext/nkf/lib/kconv.rb, line 140 140: def guess(str) 141: ::NKF::guess(str) 142: end
Returns whether input encoding is EUC-JP or not.
Note don’t expect this return value is MatchData.
Source: show
# File ext/nkf/lib/kconv.rb, line 155 155: def iseuc(str) 156: str.dup.force_encoding(EUC).valid_encoding? 157: end
Returns whether input encoding is ISO-2022-JP or not.
Source: show
# 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
Returns whether input encoding is Shift_JIS or not.
Source: show
# File ext/nkf/lib/kconv.rb, line 164 164: def issjis(str) 165: str.dup.force_encoding(SJIS).valid_encoding? 166: end
Returns whether input encoding is UTF-8 or not.
Source: show
# File ext/nkf/lib/kconv.rb, line 192 192: def isutf8(str) 193: str.dup.force_encoding(UTF8).valid_encoding? 194: end
Convert str to out_code. out_code and in_code are given as constants of Kconv.
Source: show
# 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
Convert str to EUC-JP
Source: show
# File ext/nkf/lib/kconv.rb, line 82 82: def toeuc(str) 83: kconv(str, EUC) 84: end
Convert str to ISO-2022-JP
Source: show
# File ext/nkf/lib/kconv.rb, line 73 73: def tojis(str) 74: kconv(str, JIS) 75: end
Convert self to locale encoding
Source: show
# File ext/nkf/lib/kconv.rb, line 127 127: def tolocale(str) 128: kconv(str, Encoding.locale_charmap) 129: end
Convert str to Shift_JIS
Source: show
# File ext/nkf/lib/kconv.rb, line 91 91: def tosjis(str) 92: kconv(str, SJIS) 93: end
Convert str to UTF-16
Source: show
# File ext/nkf/lib/kconv.rb, line 109 109: def toutf16(str) 110: kconv(str, UTF16) 111: end
Convert str to UTF-32
Source: show
# File ext/nkf/lib/kconv.rb, line 118 118: def toutf32(str) 119: kconv(str, UTF32) 120: end
Convert str to UTF-8
Source: show
# File ext/nkf/lib/kconv.rb, line 100 100: def toutf8(str) 101: kconv(str, UTF8) 102: end