File: C:/Ruby27-x64/share/doc/ruby/html/NKF.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>module NKF - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "./";
var index_rel_prefix = "./";
</script>
<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>
<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="module">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="./index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="./table_of_contents.html#pages">Pages</a>
<a href="./table_of_contents.html#classes">Classes</a>
<a href="./table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div class="nav-section">
<h3>Table of Contents</h3>
<ul class="link-list" role="directory">
<li><a href="#module-NKF-label-Description">Description</a>
<li><a href="#module-NKF-label-Flags">Flags</a>
<li><a href="#module-NKF-label-b+-u">-b -u</a>
<li><a href="#module-NKF-label-j+-s+-e+-w+-w16+-w32">-j -s -e -w -w16 -w32</a>
<li><a href="#module-NKF-label-J+-S+-E+-W+-W16+-W32">-J -S -E -W -W16 -W32</a>
<li><a href="#module-NKF-label-J">-J</a>
<li><a href="#module-NKF-label-S">-S</a>
<li><a href="#module-NKF-label-E">-E</a>
<li><a href="#module-NKF-label-t">-t</a>
<li><a href="#module-NKF-label-i_">-i_</a>
<li><a href="#module-NKF-label-o_">-o_</a>
<li><a href="#module-NKF-label-r">-r</a>
<li><a href="#module-NKF-label-h+--hiragana+--katakana+--katakana-hiragana">-<a href="123">h</a> –hiragana –katakana –katakana-hiragana</a>
<li><a href="#module-NKF-label-T">-T</a>
<li><a href="#module-NKF-label-l">-l</a>
<li><a href="#module-NKF-label-f-5Bm+-5B-+n-5D-5D">-f[<code>m</code> [- <code>n</code>]]</a>
<li><a href="#module-NKF-label-F">-F</a>
<li><a href="#module-NKF-label-Z">-<a href="0-3">Z</a></a>
<li><a href="#module-NKF-label-X+-x">-X -x</a>
<li><a href="#module-NKF-label-B">-<a href="0-2">B</a></a>
<li><a href="#module-NKF-label-I">-I</a>
<li><a href="#module-NKF-label-d+-c">-d -c</a>
<li><a href="#module-NKF-label-m">-<a href="BQN0">m</a></a>
<li><a href="#module-NKF-label-M">-M</a>
<li><a href="#module-NKF-label-l">-l</a>
<li><a href="#module-NKF-label-L">-<a href="uwm">L</a></a>
<li><a href="#module-NKF-label--fj+--unix+--mac+--msdos+--windows">–fj –unix –mac –msdos –windows</a>
<li><a href="#module-NKF-label--jis+--euc+--sjis+--mime+--base64">–jis –euc –sjis –mime –base64</a>
<li><a href="#module-NKF-label--jis-input+--euc-input+--sjis-input+--mime-input+--base64-input">–jis-input –euc-input –sjis-input –mime-input –base64-input</a>
<li><a href="#module-NKF-label--ic-3Dinput+codeset+--oc-3Doutput+codeset">–ic=<code>input codeset</code> –oc=<code>output codeset</code></a>
<li><a href="#module-NKF-label--fb--7Bskip-2C+html-2C+xml-2C+perl-2C+java-2C+subchar-7D">–fb-{skip, html, xml, perl, java, subchar}</a>
<li><a href="#module-NKF-label--prefix-3D+escape+character+target+character+..">–prefix= <code>escape character</code> <code>target character</code> ..</a>
<li><a href="#module-NKF-label--no-cp932ext">–no-cp932ext</a>
<li><a href="#module-NKF-label--no-best-fit-chars">–no-best-fit-chars</a>
<li><a href="#module-NKF-label--cap-input">–cap-input</a>
<li><a href="#module-NKF-label--url-input">–url-input</a>
<li><a href="#module-NKF-label--">–</a>
</ul>
</div>
<div id="class-metadata">
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-guess">::guess</a>
<li ><a href="#method-c-nkf">::nkf</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="module-NKF">
<h1 id="module-NKF" class="module">
module NKF
</h1>
<section class="description">
<p><a href="NKF.html"><code>NKF</code></a> - Ruby extension for Network Kanji Filter</p>
<h2 id="module-NKF-label-Description">Description<span><a href="#module-NKF-label-Description">¶</a> <a href="#top">↑</a></span></h2>
<p>This is a Ruby Extension version of nkf (Network Kanji Filter). It converts the first argument and returns converted result. Conversion details are specified by flags as the first argument.</p>
<p><strong>Nkf</strong> 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.</p>
<p>One of the most unique faculty of <strong>nkf</strong> 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.</p>
<p>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 <strong>-X</strong>, <strong>-x</strong> or <strong>-S</strong>.</p>
<h2 id="module-NKF-label-Flags">Flags<span><a href="#module-NKF-label-Flags">¶</a> <a href="#top">↑</a></span></h2>
<h3 id="module-NKF-label-b+-u">-b -u<span><a href="#module-NKF-label-b+-u">¶</a> <a href="#top">↑</a></span></h3>
<p>Output is buffered (DEFAULT), Output is unbuffered.</p>
<h3 id="module-NKF-label-j+-s+-e+-w+-w16+-w32">-j -s -e -w -w16 -w32<span><a href="#module-NKF-label-j+-s+-e+-w+-w16+-w32">¶</a> <a href="#top">↑</a></span></h3>
<p>Output code is ISO-2022-JP (7bit <a href="NKF.html#JIS"><code>JIS</code></a>), Shift_JIS, EUC-JP, UTF-8N, UTF-16BE, UTF-32BE. Without this option and compile option, ISO-2022-JP is assumed.</p>
<h3 id="module-NKF-label-J+-S+-E+-W+-W16+-W32">-J -S -E -W -W16 -W32<span><a href="#module-NKF-label-J+-S+-E+-W+-W16+-W32">¶</a> <a href="#top">↑</a></span></h3>
<p>Input assumption is <a href="NKF.html#JIS"><code>JIS</code></a> 7 bit, Shift_JIS, EUC-JP, UTF-8, UTF-16, UTF-32.</p>
<h4 id="module-NKF-label-J">-J<span><a href="#module-NKF-label-J">¶</a> <a href="#top">↑</a></span></h4>
<p>Assume <a href="NKF.html#JIS"><code>JIS</code></a> input. It also accepts EUC-JP. This is the default. This flag does not exclude Shift_JIS.</p>
<h4 id="module-NKF-label-S">-S<span><a href="#module-NKF-label-S">¶</a> <a href="#top">↑</a></span></h4>
<p>Assume Shift_JIS and X0201 kana input. It also accepts <a href="NKF.html#JIS"><code>JIS</code></a>. EUC-JP is recognized as X0201 kana. Without <strong>-x</strong> flag, X0201 kana (halfwidth kana) is converted into X0208.</p>
<h4 id="module-NKF-label-E">-E<span><a href="#module-NKF-label-E">¶</a> <a href="#top">↑</a></span></h4>
<p>Assume EUC-JP input. It also accepts <a href="NKF.html#JIS"><code>JIS</code></a>. Same as -J.</p>
<h3 id="module-NKF-label-t">-t<span><a href="#module-NKF-label-t">¶</a> <a href="#top">↑</a></span></h3>
<p>No conversion.</p>
<h3 id="module-NKF-label-i_">-i_<span><a href="#module-NKF-label-i_">¶</a> <a href="#top">↑</a></span></h3>
<p>Output sequence to designate JIS-kanji. (DEFAULT B)</p>
<h3 id="module-NKF-label-o_">-o_<span><a href="#module-NKF-label-o_">¶</a> <a href="#top">↑</a></span></h3>
<p>Output sequence to designate <a href="NKF.html#ASCII"><code>ASCII</code></a>. (DEFAULT B)</p>
<h3 id="module-NKF-label-r">-r<span><a href="#module-NKF-label-r">¶</a> <a href="#top">↑</a></span></h3>
<p>{de/en}crypt ROT13/47</p>
<h3 id="module-NKF-label-h+--hiragana+--katakana+--katakana-hiragana">-<a href="123">h</a> –hiragana –katakana –katakana-hiragana<span><a href="#module-NKF-label-h+--hiragana+--katakana+--katakana-hiragana">¶</a> <a href="#top">↑</a></span></h3>
<dl class="rdoc-list label-list"><dt>-h1 –hiragana
<dd>
<p>Katakana to Hiragana conversion.</p>
</dd><dt>-h2 –katakana
<dd>
<p>Hiragana to Katakana conversion.</p>
</dd><dt>-h3 –katakana-hiragana
<dd>
<p>Katakana to Hiragana and Hiragana to Katakana conversion.</p>
</dd></dl>
<h3 id="module-NKF-label-T">-T<span><a href="#module-NKF-label-T">¶</a> <a href="#top">↑</a></span></h3>
<p>Text mode output (MS-DOS)</p>
<h3 id="module-NKF-label-l">-l<span><a href="#module-NKF-label-l">¶</a> <a href="#top">↑</a></span></h3>
<p>ISO8859-1 (Latin-1) support</p>
<h3 id="module-NKF-label-f-5Bm+-5B-+n-5D-5D">-f[<code>m</code> [- <code>n</code>]]<span><a href="#module-NKF-label-f-5Bm+-5B-+n-5D-5D">¶</a> <a href="#top">↑</a></span></h3>
<p>Folding on <code>m</code> length with <code>n</code> margin in a line. Without this option, fold length is 60 and fold margin is 10.</p>
<h3 id="module-NKF-label-F">-F<span><a href="#module-NKF-label-F">¶</a> <a href="#top">↑</a></span></h3>
<p>New line preserving line folding.</p>
<h3 id="module-NKF-label-Z">-<a href="0-3">Z</a><span><a href="#module-NKF-label-Z">¶</a> <a href="#top">↑</a></span></h3>
<p>Convert X0208 alphabet (Fullwidth Alphabets) to <a href="NKF.html#ASCII"><code>ASCII</code></a>.</p>
<dl class="rdoc-list label-list"><dt>-Z -Z0
<dd>
<p>Convert X0208 alphabet to <a href="NKF.html#ASCII"><code>ASCII</code></a>.</p>
</dd><dt>-Z1
<dd>
<p>Converts X0208 kankaku to single <a href="NKF.html#ASCII"><code>ASCII</code></a> space.</p>
</dd><dt>-Z2
<dd>
<p>Converts X0208 kankaku to double <a href="NKF.html#ASCII"><code>ASCII</code></a> spaces.</p>
</dd><dt>-Z3
<dd>
<p>Replacing Fullwidth >, <, “, & into '&gt;', '&lt;', '&quot;', '&amp;' as in HTML.</p>
</dd></dl>
<h3 id="module-NKF-label-X+-x">-X -x<span><a href="#module-NKF-label-X+-x">¶</a> <a href="#top">↑</a></span></h3>
<p>Assume X0201 kana in MS-Kanji. With <strong>-X</strong> or without this option, X0201 is converted into X0208 Kana. With <strong>-x</strong>, try to preserve X0208 kana and do not convert X0201 kana to X0208. In <a href="NKF.html#JIS"><code>JIS</code></a> output, ESC-(-I is used. In <a href="NKF.html#EUC"><code>EUC</code></a> output, SSO is used.</p>
<h3 id="module-NKF-label-B">-<a href="0-2">B</a><span><a href="#module-NKF-label-B">¶</a> <a href="#top">↑</a></span></h3>
<p>Assume broken JIS-Kanji input, which lost ESC. Useful when your site is using old B-News Nihongo patch.</p>
<dl class="rdoc-list label-list"><dt>-B1
<dd>
<p>allows any char after ESC-( or ESC-$.</p>
</dd><dt>-B2
<dd>
<p>forces <a href="NKF.html#ASCII"><code>ASCII</code></a> after NL.</p>
</dd></dl>
<h3 id="module-NKF-label-I">-I<span><a href="#module-NKF-label-I">¶</a> <a href="#top">↑</a></span></h3>
<p>Replacing non iso-2022-jp char into a geta character (substitute character in Japanese).</p>
<h3 id="module-NKF-label-d+-c">-d -c<span><a href="#module-NKF-label-d+-c">¶</a> <a href="#top">↑</a></span></h3>
<p>Delete r in line feed, Add r in line feed.</p>
<h3 id="module-NKF-label-m">-<a href="BQN0">m</a><span><a href="#module-NKF-label-m">¶</a> <a href="#top">↑</a></span></h3>
<p>MIME ISO-2022-JP/ISO8859-1 decode. (DEFAULT) To see ISO8859-1 (Latin-1) -l is necessary.</p>
<dl class="rdoc-list label-list"><dt>-mB
<dd>
<p>Decode MIME base64 encoded stream. Remove header or other part before</p>
</dd></dl>
<p>conversion.</p>
<dl class="rdoc-list label-list"><dt>-mQ
<dd>
<p>Decode MIME quoted stream. '_' in quoted stream is converted to space.</p>
</dd><dt>-mN
<dd>
<p>Non-strict decoding.</p>
</dd></dl>
<p>It allows line break in the middle of the base64 encoding.</p>
<dl class="rdoc-list label-list"><dt>-m0
<dd>
<p>No MIME decode.</p>
</dd></dl>
<h3 id="module-NKF-label-M">-M<span><a href="#module-NKF-label-M">¶</a> <a href="#top">↑</a></span></h3>
<p>MIME encode. Header style. All <a href="NKF.html#ASCII"><code>ASCII</code></a> code and control characters are intact. Kanji conversion is performed before encoding, so this cannot be used as a picture encoder.</p>
<dl class="rdoc-list label-list"><dt>-MB
<dd>
<p>MIME encode <a href="Base64.html"><code>Base64</code></a> stream.</p>
</dd><dt>-MQ
<dd>
<p>Perfome quoted encoding.</p>
</dd></dl>
<h3 id="module-NKF-label-l">-l<span><a href="#module-NKF-label-l">¶</a> <a href="#top">↑</a></span></h3>
<p>Input and output code is ISO8859-1 (Latin-1) and ISO-2022-JP. <strong>-s</strong>, <strong>-e</strong> and <strong>-x</strong> are not compatible with this option.</p>
<h3 id="module-NKF-label-L">-<a href="uwm">L</a><span><a href="#module-NKF-label-L">¶</a> <a href="#top">↑</a></span></h3>
<p>new line mode Without this option, nkf doesn't convert line breaks.</p>
<dl class="rdoc-list label-list"><dt>-Lu
<dd>
<p>unix (LF)</p>
</dd><dt>-Lw
<dd>
<p>windows (CRLF)</p>
</dd><dt>-Lm
<dd>
<p>mac (CR)</p>
</dd></dl>
<h3 id="module-NKF-label--fj+--unix+--mac+--msdos+--windows">–fj –unix –mac –msdos –windows<span><a href="#module-NKF-label--fj+--unix+--mac+--msdos+--windows">¶</a> <a href="#top">↑</a></span></h3>
<p>convert for these system</p>
<h3 id="module-NKF-label--jis+--euc+--sjis+--mime+--base64">–jis –euc –sjis –mime –base64<span><a href="#module-NKF-label--jis+--euc+--sjis+--mime+--base64">¶</a> <a href="#top">↑</a></span></h3>
<p>convert for named code</p>
<h3 id="module-NKF-label--jis-input+--euc-input+--sjis-input+--mime-input+--base64-input">–jis-input –euc-input –sjis-input –mime-input –base64-input<span><a href="#module-NKF-label--jis-input+--euc-input+--sjis-input+--mime-input+--base64-input">¶</a> <a href="#top">↑</a></span></h3>
<p>assume input system</p>
<h3 id="module-NKF-label--ic-3Dinput+codeset+--oc-3Doutput+codeset">–ic=<code>input codeset</code> –oc=<code>output codeset</code><span><a href="#module-NKF-label--ic-3Dinput+codeset+--oc-3Doutput+codeset">¶</a> <a href="#top">↑</a></span></h3>
<p><a href="Set.html"><code>Set</code></a> the input or output codeset. <a href="NKF.html"><code>NKF</code></a> supports following codesets and those codeset name are case insensitive.</p>
<dl class="rdoc-list label-list"><dt>ISO-2022-JP
<dd>
<p>a.k.a. RFC1468, 7bit <a href="NKF.html#JIS"><code>JIS</code></a>, JUNET</p>
</dd><dt>EUC-JP (eucJP-nkf)
<dd>
<p>a.k.a. AT&T <a href="NKF.html#JIS"><code>JIS</code></a>, Japanese <a href="NKF.html#EUC"><code>EUC</code></a>, UJIS</p>
</dd><dt>eucJP-ascii
<dd>
<p>a.k.a. x-eucjp-open-19970715-ascii</p>
</dd><dt>eucJP-ms
<dd>
<p>a.k.a. x-eucjp-open-19970715-ms</p>
</dd><dt>CP51932
<dd>
<p>Microsoft Version of EUC-JP.</p>
</dd><dt>Shift_JIS
<dd>
<p><a href="NKF.html#SJIS"><code>SJIS</code></a>, MS-Kanji</p>
</dd><dt>Windows-31J
<dd>
<p>a.k.a. CP932</p>
</dd><dt>UTF-8
<dd>
<p>same as UTF-8N</p>
</dd><dt>UTF-8N
<dd>
<p>UTF-8 without BOM</p>
</dd><dt>UTF-8-BOM
<dd>
<p>UTF-8 with BOM</p>
</dd><dt>UTF-16
<dd>
<p>same as UTF-16BE</p>
</dd><dt>UTF-16BE
<dd>
<p>UTF-16 Big Endian without BOM</p>
</dd><dt>UTF-16BE-BOM
<dd>
<p>UTF-16 Big Endian with BOM</p>
</dd><dt>UTF-16LE
<dd>
<p>UTF-16 Little Endian without BOM</p>
</dd><dt>UTF-16LE-BOM
<dd>
<p>UTF-16 Little Endian with BOM</p>
</dd><dt>UTF-32
<dd>
<p>same as UTF-32BE</p>
</dd><dt>UTF-32BE
<dd>
<p>UTF-32 Big Endian without BOM</p>
</dd><dt>UTF-32BE-BOM
<dd>
<p>UTF-32 Big Endian with BOM</p>
</dd><dt>UTF-32LE
<dd>
<p>UTF-32 Little Endian without BOM</p>
</dd><dt>UTF-32LE-BOM
<dd>
<p>UTF-32 Little Endian with BOM</p>
</dd><dt>UTF8-MAC
<dd>
<p>NKDed UTF-8, a.k.a. UTF8-NFD (input only)</p>
</dd></dl>
<h3 id="module-NKF-label--fb--7Bskip-2C+html-2C+xml-2C+perl-2C+java-2C+subchar-7D">–fb-{skip, html, xml, perl, java, subchar}<span><a href="#module-NKF-label--fb--7Bskip-2C+html-2C+xml-2C+perl-2C+java-2C+subchar-7D">¶</a> <a href="#top">↑</a></span></h3>
<p>Specify the way that nkf handles unassigned characters. Without this option, –fb-skip is assumed.</p>
<h3 id="module-NKF-label--prefix-3D+escape+character+target+character+..">–prefix= <code>escape character</code> <code>target character</code> ..<span><a href="#module-NKF-label--prefix-3D+escape+character+target+character+..">¶</a> <a href="#top">↑</a></span></h3>
<p>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.</p>
<h3 id="module-NKF-label--no-cp932ext">–no-cp932ext<span><a href="#module-NKF-label--no-cp932ext">¶</a> <a href="#top">↑</a></span></h3>
<p>Handle the characters extended in CP932 as unassigned characters.</p>
<h2 id="module-NKF-label--no-best-fit-chars">–no-best-fit-chars<span><a href="#module-NKF-label--no-best-fit-chars">¶</a> <a href="#top">↑</a></span></h2>
<p>When Unicode to Encoded byte conversion, don't convert characters which is not round trip safe. When Unicode to Unicode conversion, with this and -x option, nkf can be used as UTF converter. (In other words, without this and -x option, nkf doesn't save some characters)</p>
<p>When nkf convert string which related to path, you should use this opion.</p>
<h3 id="module-NKF-label--cap-input">–cap-input<span><a href="#module-NKF-label--cap-input">¶</a> <a href="#top">↑</a></span></h3>
<p>Decode hex encoded characters.</p>
<h3 id="module-NKF-label--url-input">–url-input<span><a href="#module-NKF-label--url-input">¶</a> <a href="#top">↑</a></span></h3>
<p>Unescape percent escaped characters.</p>
<h3 id="module-NKF-label--">–<span><a href="#module-NKF-label--">¶</a> <a href="#top">↑</a></span></h3>
<p>Ignore rest of -option.</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section class="constants-list">
<header>
<h3>Constants</h3>
</header>
<dl>
<dt id="ASCII">ASCII
<dd>
<dt id="AUTO">AUTO
<dd>
<dt id="BINARY">BINARY
<dd>
<dt id="EUC">EUC
<dd>
<dt id="JIS">JIS
<dd>
<dt id="NKF_RELEASE_DATE">NKF_RELEASE_DATE
<dd><p>Release date of nkf</p>
<dt id="NKF_VERSION">NKF_VERSION
<dd><p>Version of nkf</p>
<dt id="NOCONV">NOCONV
<dd>
<dt id="SJIS">SJIS
<dd>
<dt id="UNKNOWN">UNKNOWN
<dd>
<dt id="UTF16">UTF16
<dd>
<dt id="UTF32">UTF32
<dd>
<dt id="UTF8">UTF8
<dd>
<dt id="VERSION">VERSION
<dd><p>Full version string of nkf</p>
</dl>
</section>
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-guess" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
guess(str) → encoding
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns guessed encoding of <em>str</em> by nkf routine.</p>
<div class="method-source-code" id="guess-source">
<pre>static VALUE
rb_nkf_guess(VALUE obj, VALUE src)
{
reinit();
input_ctr = 0;
input = (unsigned char *)StringValuePtr(src);
i_len = RSTRING_LENINT(src);
guess_f = TRUE;
kanji_convert( NULL );
guess_f = FALSE;
return rb_enc_from_encoding(rb_nkf_enc_get(get_guessed_code()));
}</pre>
</div>
</div>
</div>
<div id="method-c-nkf" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
nkf(opt, str) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Convert <em>str</em> and return converted result. Conversion details are specified by <em>opt</em> as <a href="String.html"><code>String</code></a>.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'nkf'</span>
<span class="ruby-identifier">output</span> = <span class="ruby-constant">NKF</span>.<span class="ruby-identifier">nkf</span>(<span class="ruby-string">"-s"</span>, <span class="ruby-identifier">input</span>)
</pre>
<div class="method-source-code" id="nkf-source">
<pre>static VALUE
rb_nkf_convert(VALUE obj, VALUE opt, VALUE src)
{
VALUE tmp;
reinit();
nkf_split_options(StringValueCStr(opt));
if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given");
switch (nkf_enc_to_index(output_encoding)) {
case UTF_8_BOM: output_encoding = nkf_enc_from_index(UTF_8); break;
case UTF_16BE_BOM: output_encoding = nkf_enc_from_index(UTF_16BE); break;
case UTF_16LE_BOM: output_encoding = nkf_enc_from_index(UTF_16LE); break;
case UTF_32BE_BOM: output_encoding = nkf_enc_from_index(UTF_32BE); break;
case UTF_32LE_BOM: output_encoding = nkf_enc_from_index(UTF_32LE); break;
}
output_bom_f = FALSE;
incsize = INCSIZE;
input_ctr = 0;
input = (unsigned char *)StringValuePtr(src);
i_len = RSTRING_LENINT(src);
tmp = rb_str_new(0, i_len*3 + 10);
output_ctr = 0;
output = (unsigned char *)RSTRING_PTR(tmp);
o_len = RSTRING_LENINT(tmp);
*output = '\0';
/* use _result_ begin*/
result = tmp;
kanji_convert(NULL);
result = Qnil;
/* use _result_ end */
rb_str_set_len(tmp, output_ctr);
if (mimeout_f)
rb_enc_associate(tmp, rb_usascii_encoding());
else
rb_enc_associate(tmp, rb_nkf_enc_get(nkf_enc_name(output_encoding)));
return tmp;
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>