Module | NKF |
In: |
ext/nkf/nkf.c
|
NKF - Ruby extension for Network Kanji Filter
This is a Ruby Extension version of nkf (Netowrk Kanji Filter). It converts the first argument and return converted result. Conversion details are specified by flags as the first argument.
Nkf is a yet another kanji code converter among networks, hosts and terminals. It converts input kanji code to designated kanji code such as ISO-2022-JP, Shift_JIS, EUC-JP, UTF-8 or UTF-16.
One of the most unique faculty of nkf is the guess of the input kanji encodings. It currently recognizes ISO-2022-JP, Shift_JIS, EUC-JP, UTF-8 and UTF-16. So users needn‘t set the input kanji code explicitly.
By default, X0201 kana is converted into X0208 kana. For X0201 kana, SO/SI, SSO and ESC-(-I methods are supported. For automatic code detection, nkf assumes no X0201 kana in Shift_JIS. To accept X0201 in Shift_JIS, use -X, -x or -S.
Output is buffered (DEFAULT), Output is unbuffered.
Output code is ISO-2022-JP (7bit JIS), Shift_JIS, EUC-JP, UTF-8N, UTF-16BE. Without this option and compile option, ISO-2022-JP is assumed.
Input assumption is JIS 7 bit, Shift_JIS, EUC-JP, UTF-8, UTF-16LE.
Assume JIS input. It also accepts EUC-JP. This is the default. This flag does not exclude Shift_JIS.
Assume Shift_JIS and X0201 kana input. It also accepts JIS. EUC-JP is recognized as X0201 kana. Without -x flag, X0201 kana (halfwidth kana) is converted into X0208.
Assume EUC-JP input. It also accepts JIS. Same as -J.
No conversion.
Output sequence to designate JIS-kanji. (DEFAULT B)
Output sequence to designate ASCII. (DEFAULT B)
{de/en}crypt ROT13/47
Text mode output (MS-DOS)
ISO8859-1 (Latin-1) support
Folding on m length with n margin in a line. Without this option, fold length is 60 and fold margin is 10.
New line preserving line folding.
Convert X0208 alphabet (Fullwidth Alphabets) to ASCII.
Assume X0201 kana in MS-Kanji. With -X or without this option, X0201 is converted into X0208 Kana. With -x, try to preserve X0208 kana and do not convert X0201 kana to X0208. In JIS output, ESC-(-I is used. In EUC output, SSO is used.
Assume broken JIS-Kanji input, which lost ESC. Useful when your site is using old B-News Nihongo patch.
Replacing non iso-2022-jp char into a geta character (substitute character in Japanese).
Delete \r in line feed, Add \r in line feed.
MIME ISO-2022-JP/ISO8859-1 decode. (DEFAULT) To see ISO8859-1 (Latin-1) -l is necessary.
conversion.
It allows line break in the middle of the base64 encoding.
MIME encode. Header style. All ASCII code and control characters are intact. Kanji conversion is performed before encoding, so this cannot be used as a picture encoder.
Input and output code is ISO8859-1 (Latin-1) and ISO-2022-JP. -s, -e and -x are not compatible with this option.
new line mode Without this option, nkf doesn‘t convert line breaks.
convert for these system
convert for named code
assume input system
Set the input or output codeset. NKF supports following codesets and those codeset name are case insensitive.
Specify the way that nkf handles unassigned characters. Without this option, —fb-skip is assumed.
When nkf converts to Shift_JIS, nkf adds a specified escape character to specified 2nd byte of Shift_JIS characters. 1st byte of argument is the escape character and following bytes are target characters.
Handle the characters extended in CP932 as unassigned characters.
Decode hex encoded characters.
Unescape percent escaped characters.
Ignore rest of -option.
AUTO | = | INT2FIX(_AUTO) | Auto-Detect | |
JIS | = | INT2FIX(_JIS) | ISO-2022-JP | |
EUC | = | INT2FIX(_EUC) | EUC-JP | |
SJIS | = | INT2FIX(_SJIS) | Shift_JIS | |
BINARY | = | INT2FIX(_BINARY) | BINARY | |
NOCONV | = | INT2FIX(_NOCONV) | No conversion | |
ASCII | = | INT2FIX(_ASCII) | ASCII | |
UTF8 | = | INT2FIX(_UTF8) | UTF-8 | |
UTF16 | = | INT2FIX(_UTF16) | UTF-16 | |
UTF32 | = | INT2FIX(_UTF32) | UTF-32 | |
UNKNOWN | = | INT2FIX(_UNKNOWN) | UNKNOWN | |
VERSION | = | rb_str_new2(RUBY_NKF_VERSION) | Full version string of nkf | |
NKF_VERSION | = | rb_str_new2(NKF_VERSION) | Version of nkf | |
NKF_RELEASE_DATE | = | rb_str_new2(NKF_RELEASE_DATE) | Release date of nkf |
guess2 | -> | guess |
Returns guessed encoding of str as integer.
Algorithm described in: Ken Lunde. `Understanding Japanese Information Processing’ Sebastopol, CA: O‘Reilly & Associates.
case NKF.guess1(input) when NKF::JIS "ISO-2022-JP" when NKF::SJIS "Shift_JIS" when NKF::EUC "EUC-JP" when NKF::UNKNOWN "UNKNOWN(ASCII)" when NKF::BINARY "BINARY" end
Returns guessed encoding of str as integer by nkf routine.
case NKF.guess(input) when NKF::ASCII "ASCII" when NKF::JIS "ISO-2022-JP" when NKF::SJIS "Shift_JIS" when NKF::EUC "EUC-JP" when NKF::UTF8 "UTF-8" when NKF::UTF16 "UTF-16" when NKF::UNKNOWN "UNKNOWN" when NKF::BINARY "BINARY" end
ruby-doc.org is a service of James Britt and Neurogami, a Ruby application development company in Phoenix, AZ.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.