📄 glib-character-set-conversion.html
字号:
<a class="link" href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> converter, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *bytes_read, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *bytes_written, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts a string from one character set to another. </p><p>Note that you should use <a class="link" href="glib-Character-Set-Conversion.html#g-iconv"><code class="function">g_iconv()</code></a> for streaming conversions<sup>[<a name="streaming-state" href="#ftn.streaming-state" class="footnote">2</a>]</sup>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>str</code></em> :</span></p></td><td> the string to convert</td></tr><tr><td><p><span class="term"><em class="parameter"><code>len</code></em> :</span></p></td><td> the length of the string, or -1 if the string is nul-terminated<sup>[<a href="glib-Character-Set-Conversion.html#ftn.nul-unsafe" class="footnoteref">1</a>]</sup>. </td></tr><tr><td><p><span class="term"><em class="parameter"><code>converter</code></em> :</span></p></td><td> conversion descriptor from <a class="link" href="glib-Character-Set-Conversion.html#g-iconv-open"><code class="function">g_iconv_open()</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>bytes_read</code></em> :</span></p></td><td> location to store the number of bytes in the input string that were successfully converted, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. Even if the conversion was successful, this may be less than <em class="parameter"><code>len</code></em> if there were partial characters at the end of the input. If the error <a class="link" href="glib-Character-Set-Conversion.html#G-CONVERT-ERROR-ILLEGAL-SEQUENCE:CAPS"><span class="type">G_CONVERT_ERROR_ILLEGAL_SEQUENCE</span></a> occurs, the value stored will the byte offset after the last valid input sequence.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>bytes_written</code></em> :</span></p></td><td> the number of bytes stored in the output buffer (not including the terminating nul).</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> location to store the error occuring, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore errors. Any of the errors in <a class="link" href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> may occur.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> If the conversion was successful, a newly allocated nul-terminated string, which must be freed with <a class="link" href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>. Otherwise <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> and <em class="parameter"><code>error</code></em> will be set.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2990904"></a><h3><a name="G-CONVERT-ERROR:CAPS"></a>G_CONVERT_ERROR</h3><a class="indexterm" name="id2990918"></a><pre class="programlisting">#define G_CONVERT_ERROR g_convert_error_quark()</pre><p>Error domain for character set conversions. Errors in this domain willbe from the <a class="link" href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> enumeration. See <a class="link" href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on error domains.</p></div><hr><div class="refsect2" lang="en"><a name="id2990952"></a><h3><a name="g-iconv-open"></a>g_iconv_open ()</h3><a class="indexterm" name="id2990964"></a><pre class="programlisting"><a class="link" href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> g_iconv_open (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *to_codeset, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *from_codeset);</pre><p>Same as the standard UNIX routine <code class="function">iconv_open()</code>, butmay be implemented via libiconv on UNIX flavors that lacka native implementation.</p><p>GLib provides <a class="link" href="glib-Character-Set-Conversion.html#g-convert"><code class="function">g_convert()</code></a> and <a class="link" href="glib-Character-Set-Conversion.html#g-locale-to-utf8"><code class="function">g_locale_to_utf8()</code></a> which are likelymore convenient than the raw iconv wrappers.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>to_codeset</code></em> :</span></p></td><td> destination codeset</td></tr><tr><td><p><span class="term"><em class="parameter"><code>from_codeset</code></em> :</span></p></td><td> source codeset</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> a "conversion descriptor", or (GIConv)-1 if opening the converter failed.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2991087"></a><h3><a name="g-iconv"></a>g_iconv ()</h3><a class="indexterm" name="id2991100"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gsize">gsize</a> g_iconv (<a class="link" href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> converter, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **inbuf, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *inbytes_left, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **outbuf, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *outbytes_left);</pre><p>Same as the standard UNIX routine <code class="function">iconv()</code>, butmay be implemented via libiconv on UNIX flavors that lacka native implementation.</p><p>GLib provides <a class="link" href="glib-Character-Set-Conversion.html#g-convert"><code class="function">g_convert()</code></a> and <a class="link" href="glib-Character-Set-Conversion.html#g-locale-to-utf8"><code class="function">g_locale_to_utf8()</code></a> which are likelymore convenient than the raw iconv wrappers.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>converter</code></em> :</span></p></td><td> conversion descriptor from <a class="link" href="glib-Character-Set-Conversion.html#g-iconv-open"><code class="function">g_iconv_open()</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>inbuf</code></em> :</span></p></td><td> bytes to convert</td></tr><tr><td><p><span class="term"><em class="parameter"><code>inbytes_left</code></em> :</span></p></td><td> inout parameter, bytes remaining to convert in <em class="parameter"><code>inbuf</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>outbuf</code></em> :</span></p></td><td> converted output bytes</td></tr><tr><td><p><span class="term"><em class="parameter"><code>outbytes_left</code></em> :</span></p></td><td> inout parameter, bytes available to fill in <em class="parameter"><code>outbuf</code></em></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> count of non-reversible conversions, or -1 on error</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2991309"></a><h3><a name="g-iconv-close"></a>g_iconv_close ()</h3><a class="indexterm" name="id2991322"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_iconv_close (<a class="link" href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> converter);</pre><p>Same as the standard UNIX routine <code class="function">iconv_close()</code>, butmay be implemented via libiconv on UNIX flavors that lacka native implementation. Should be called to clean upthe conversion descriptor from <a class="link" href="glib-Character-Set-Conversion.html#g-iconv-open"><code class="function">g_iconv_open()</code></a> whenyou are done converting things.</p><p>GLib provides <a class="link" href="glib-Character-Set-Conversion.html#g-convert"><code class="function">g_convert()</code></a> and <a class="link" href="glib-Character-Set-Conversion.html#g-locale-to-utf8"><code class="function">g_locale_to_utf8()</code></a> which are likelymore convenient than the raw iconv wrappers.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>converter</code></em> :</span></p></td><td> a conversion descriptor from <a class="link" href="glib-Character-Set-Conversion.html#g-iconv-open"><code class="function">g_iconv_open()</code></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> -1 on error, 0 on success</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2991445"></a><h3><a name="g-locale-to-utf8"></a>g_locale_to_utf8 ()</h3><a class="indexterm" name="id2991458"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* g_locale_to_utf8 (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *opsysstring, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> len, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *bytes_read, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *bytes_written, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts a string which is in the encoding used for strings bythe C runtime (usually the same as that used by the operatingsystem) in the <a class="link" href="glib-running.html#setlocale" title="Locale">current locale</a> into aUTF-8 string.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -