1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
<?xml version="1.0" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iconv</title>
<link href="rd.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<h1><a name="label:0" id="label:0">Summary</a></h1><!-- RDLabel: "Summary" -->
<p>Ruby extension for codeset conversion.</p>
<h2><a name="label:1" id="label:1">License</a></h2><!-- RDLabel: "License" -->
<pre>$Revision: 0.4.5.0 $
$Copyleft: (c) 1999-2001 Nobuyoshi.Nakada <nobu.nokada@softhome.net> $</pre>
<p>This library is free software; you can redistribute it and/or
modify it under the terms of
<a href="http://www.gnu.org/copyleft/lesser.txt">the GNU Lesser General Public License</a>
as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.</p>
<p>This library is distributed in the hope that it will be useful,
but <em>WITHOUT ANY WARRANTY</em>; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
<a href="http://www.gnu.org/copyleft/lesser.txt">the GNU Lesser General Public License</a>
for more details.</p>
<h1><a name="label:2" id="label:2">Abstract</a></h1><!-- RDLabel: "Abstract" -->
<p>Iconv is a wrapper class for UNIX 95 <code>iconv()</code> function family, which
translates string between various coding systems.</p>
<p>See <a href="http://www.opengroup.org/">Open Group</a>'s on-line documents for more details.</p>
<ul>
<li><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html">iconv.h</a></li>
<li><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/iconv_open.html">iconv_open()</a></li>
<li><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.html">iconv()</a></li>
<li><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/iconv_close.html">iconv_close()</a></li>
</ul>
<p>Which coding systems are available, it depends on the platform.</p>
<h1><a name="label:3" id="label:3">Classes & Modules</a></h1><!-- RDLabel: "Classes & Modules" -->
<h2><a name="label:4" id="label:4">Iconv</a></h2><!-- RDLabel: "Iconv" -->
<h3><a name="label:5" id="label:5">Class methods</a></h3><!-- RDLabel: "Class methods" -->
<dl>
<dt><a name="label:6" id="label:6"><code>Iconv.new(<var>to</var>, <var>from</var>)</code></a></dt><!-- RDLabel: "Iconv.new" -->
<dd>
<p>Creates new code converter from a coding-system designated with <var>from</var>
to another one designated with <var>to</var>.</p>
<dl>
<dt><a name="label:7" id="label:7">Parameters
</a></dt><!-- RDLabel: "Parameters
" -->
<dd>
<dl>
<dt><a name="label:8" id="label:8"><var>to</var>
</a></dt><!-- RDLabel: "to
" -->
<dd>
<p>coding-system name for destination.</p>
</dd>
<dt><a name="label:9" id="label:9"><var>from</var>
</a></dt><!-- RDLabel: "from
" -->
<dd>
<p>coding-system name for source.</p>
</dd>
</dl>
</dd>
<dt><a name="label:10" id="label:10">Exceptions
</a></dt><!-- RDLabel: "Exceptions
" -->
<dd>
<dl>
<dt><a name="label:11" id="label:11"><code>TypeError</code>
</a></dt><!-- RDLabel: "TypeError
" -->
<dd>
<p>if <var>to</var> or <var>from</var> aren't String</p>
</dd>
<dt><a name="label:12" id="label:12"><code>ArgumentError</code>
</a></dt><!-- RDLabel: "ArgumentError
" -->
<dd>
<p>if designated converter couldn't find out.</p>
</dd>
<dt><a name="label:13" id="label:13"><code>SystemCallError</code>
</a></dt><!-- RDLabel: "SystemCallError
" -->
<dd>
<p>when <code>iconv_open(3)</code> failed.</p>
</dd>
</dl>
</dd>
</dl></dd>
<dt><a name="label:14" id="label:14"><code>Iconv.open(<var>to</var>, <var>from</var>)</code></a></dt><!-- RDLabel: "Iconv.open" -->
<dd>
<p>Equivalents to <a href="#label:6">Iconv.new</a> except with in the case of called
with a block, yields with the new instance and closes it, and
returns the result which returned from the block.</p></dd>
</dl>
<dl>
<dt><a name="label:15" id="label:15"><code>Iconv.iconv(<var>to</var>, <var>from</var>, *<var>strs</var>)</code></a></dt><!-- RDLabel: "Iconv.iconv" -->
<dd>
<p>Shorthand for</p>
<pre>Iconv.new(to, from) {|cd| (strs + nil).collect {|s| cd.iconv(s)}}</pre>
<dl>
<dt><a name="label:16" id="label:16">Parameters
</a></dt><!-- RDLabel: "Parameters
" -->
<dd>
<dl>
<dt><a name="label:17" id="label:17"><var>to</var>, <var>from</var>
</a></dt><!-- RDLabel: "to, from
" -->
<dd>
<p>see <a href="#label:6">Iconv.new</a>.</p>
</dd>
<dt><a name="label:18" id="label:18"><var>strs</var>
</a></dt><!-- RDLabel: "strs
" -->
<dd>
<p>strings to be converted.</p>
</dd>
</dl>
</dd>
<dt><a name="label:19" id="label:19">Exceptions
</a></dt><!-- RDLabel: "Exceptions
" -->
<dd>
<p>exceptions thrown by <a href="#label:6">Iconv.new</a> and <a href="#label:22">Iconv#iconv</a>.</p>
</dd>
</dl></dd>
</dl>
<h3><a name="label:20" id="label:20">Instance methods</a></h3><!-- RDLabel: "Instance methods" -->
<dl>
<dt><a name="label:21" id="label:21"><code>Iconv#close</code></a></dt><!-- RDLabel: "Iconv#close" -->
<dd>
<p>Finishes conversion.</p>
<ul>
<li>After calling this, invoking method <a href="#label:22">Iconv#iconv</a> will cause
exception, but multiple calls of <code>close</code> are guaranteed to
end successfully.</li>
<li>Returns a string contains the byte sequence to change the
output buffer to its initial shift state.</li>
</ul></dd>
</dl>
<dl>
<dt><a name="label:22" id="label:22"><code>Iconv#iconv(<var>str</var>, [ <var>start</var> = <var>0</var>, [ <var>length</var> = -<var>1</var> ] ])</code></a></dt><!-- RDLabel: "Iconv#iconv" -->
<dd>
<p>Converts string and returns converted one.</p>
<ul>
<li>In the case of <var>str</var> is <code>String</code>, converts <code>str[start, length]</code>.
Returns converted string.</li>
<li>In the case of <var>str</var> is <code>nil</code>, places <var>converter</var>
itself into initial shift state and just returns a string contains
the byte sequence to change the output buffer to its initial shift
state.</li>
<li>Otherwise, causes exception.</li>
</ul>
<dl>
<dt><a name="label:23" id="label:23">Parameters
</a></dt><!-- RDLabel: "Parameters
" -->
<dd>
<dl>
<dt><a name="label:24" id="label:24"><var>str</var>
</a></dt><!-- RDLabel: "str
" -->
<dd>
<p>string to be converted or <code>nil</code>.</p>
</dd>
<dt><a name="label:25" id="label:25"><var>start</var>
</a></dt><!-- RDLabel: "start
" -->
<dd>
<p>starting offset.</p>
</dd>
<dt><a name="label:26" id="label:26"><var>length</var>
</a></dt><!-- RDLabel: "length
" -->
<dd>
<p>conversion length,
<code>nil</code> or <code>-1</code> means whole string from <code>start</code>.</p>
</dd>
</dl>
</dd>
<dt><a name="label:27" id="label:27">Exceptions
</a></dt><!-- RDLabel: "Exceptions
" -->
<dd>
<ul>
<li><a href="#label:34">Iconv::IllegalSequence</a></li>
<li><a href="#label:37">Iconv::InvalidCharacter</a></li>
<li><a href="#label:40">Iconv::OutOfRange</a></li>
</ul>
</dd>
</dl></dd>
</dl>
<h1><a name="label:28" id="label:28">Exceptions</a></h1><!-- RDLabel: "Exceptions" -->
<h2><a name="label:29" id="label:29">Iconv::Failure</a></h2><!-- RDLabel: "Iconv::Failure" -->
<p>Base exceptional attributes from <a href="#label:4">Iconv</a>.</p>
<h3><a name="label:30" id="label:30">Instance methods</a></h3><!-- RDLabel: "Instance methods" -->
<dl>
<dt><a name="label:31" id="label:31"><code>Iconv::Failure#success</code></a></dt><!-- RDLabel: "Iconv::Failure#success" -->
<dd>
<p>Returns string(s) translated successfully until the exception occurred.</p>
<ul>
<li>In the case of failure occurred within <a href="#label:15">Iconv.iconv</a>, returned
value is an array of strings translated successfully preceding
failure and the last element is string on the way.</li>
</ul></dd>
</dl>
<dl>
<dt><a name="label:32" id="label:32"><code>Iconv::Failure#failed</code></a></dt><!-- RDLabel: "Iconv::Failure#failed" -->
<dd>
<p>Returns substring of the original string passed to <a href="#label:4">Iconv</a> that
starts at the character caused the exception. </p></dd>
</dl>
<dl>
<dt><a name="label:33" id="label:33"><code>Iconv::Failure#inspect</code></a></dt><!-- RDLabel: "Iconv::Failure#inspect" -->
<dd>
<p>Returns inspected string like as: #<<code>type</code>: "<code>success</code>", "<code>failed</code>"></p></dd>
</dl>
<h2><a name="label:34" id="label:34">Iconv::IllegalSequence</a></h2><!-- RDLabel: "Iconv::IllegalSequence" -->
<p>Exception in the case of any illegal sequence detected.</p>
<h3><a name="label:35" id="label:35">Superclass</a></h3><!-- RDLabel: "Superclass" -->
<p><code>ArgumentError</code></p>
<h3><a name="label:36" id="label:36">Included Modules</a></h3><!-- RDLabel: "Included Modules" -->
<p><a href="#label:29">Iconv::Failure</a></p>
<h2><a name="label:37" id="label:37">Iconv::InvalidCharacter</a></h2><!-- RDLabel: "Iconv::InvalidCharacter" -->
<p>Exception in the case of output coding system can't express the character.</p>
<h3><a name="label:38" id="label:38">Superclass</a></h3><!-- RDLabel: "Superclass" -->
<p><code>ArgumentError</code></p>
<h3><a name="label:39" id="label:39">Included Modules</a></h3><!-- RDLabel: "Included Modules" -->
<p><a href="#label:29">Iconv::Failure</a></p>
<h2><a name="label:40" id="label:40">Iconv::OutOfRange</a></h2><!-- RDLabel: "Iconv::OutOfRange" -->
<p>Iconv library internal error. Must not occur.</p>
<h3><a name="label:41" id="label:41">Superclass</a></h3><!-- RDLabel: "Superclass" -->
<p><code>RuntimeError</code></p>
<h3><a name="label:42" id="label:42">Included Modules</a></h3><!-- RDLabel: "Included Modules" -->
<p><a href="#label:29">Iconv::Failure</a></p>
<h2><a name="label:43" id="label:43">Example</a></h2><!-- RDLabel: "Example" -->
<ol>
<li><p>Instantiate a new <a href="#label:4">Iconv</a>, use method <a href="#label:22">Iconv#iconv</a>.</p>
<pre>cd = Iconv.new(to, from)
begin
input.each {|s| output << cd.iconv(s)}
output << cd.iconv(nil) # don't forget this
ensure
cd.close
end</pre></li>
<li><p>Invoke <a href="#label:6">Iconv.new</a> with a block.</p>
<pre>Iconv.new(to, from) do |cd|
input.each {|s| output << cd.iconv(s)}
output << cd.iconv(nil)
end</pre></li>
<li><p>Shorthand for (2).</p>
<pre>Iconv.iconv(to, from, *input.to_a)</pre></li>
</ol>
</body>
</html>
|