📄 glib-character-set-conversion.html
字号:
<span class="term"><em class="parameter"><code>str</code></em> :</span></td><td> the string to convert</td></tr><tr><td><span class="term"><em class="parameter"><code>len</code></em> :</span></td><td> the length of the string, or -1 if the string is nul-terminated<sup>[<a name="nul-unsafe" href="#ftn.nul-unsafe">1</a>]</sup>. </td></tr><tr><td><span class="term"><em class="parameter"><code>to_codeset</code></em> :</span></td><td> name of character set into which to convert <em class="parameter"><code>str</code></em></td></tr><tr><td><span class="term"><em class="parameter"><code>from_codeset</code></em> :</span></td><td> character set of <em class="parameter"><code>str</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_read</code></em> :</span></td><td> location to store the number of bytes in the input string that were successfully converted, or <code class="literal">NULL</code>. 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 <span class="type">G_CONVERT_ERROR_ILLEGAL_SEQUENCE</span> occurs, the value stored will the byte offset after the last valid input sequence.</td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_written</code></em> :</span></td><td> the number of bytes stored in the output buffer (not including the terminating nul).</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> location to store the error occuring, or <code class="literal">NULL</code> to ignore errors. Any of the errors in <a href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> may occur.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> If the conversion was successful, a newly allocated nul-terminated string, which must be freed with <a href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>. Otherwise <code class="literal">NULL</code> 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="id2961861"></a><h3><a name="g-convert-with-fallback"></a>g_convert_with_fallback ()</h3><a class="indexterm" name="id2961872"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_convert_with_fallback (const <a href="glib-Basic-Types.html#gchar">gchar</a> *str, <a href="glib-Basic-Types.html#gssize">gssize</a> len, const <a href="glib-Basic-Types.html#gchar">gchar</a> *to_codeset, const <a href="glib-Basic-Types.html#gchar">gchar</a> *from_codeset, <a href="glib-Basic-Types.html#gchar">gchar</a> *fallback, <a href="glib-Basic-Types.html#gsize">gsize</a> *bytes_read, <a href="glib-Basic-Types.html#gsize">gsize</a> *bytes_written, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts a string from one character set to another, possiblyincluding fallback sequences for characters not representablein the output. Note that it is not guaranteed that the specificationfor the fallback sequences in <em class="parameter"><code>fallback</code></em> will be honored. Somesystems may do a approximate conversion from <em class="parameter"><code>from_codeset</code></em>to <em class="parameter"><code>to_codeset</code></em> in their <code class="function">iconv()</code> functions, in which case GLib will simply return that approximate conversion.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>str</code></em> :</span></td><td> the string to convert</td></tr><tr><td><span class="term"><em class="parameter"><code>len</code></em> :</span></td><td> the length of the string, or -1 if the string is nul-terminated<sup>[<a href="#ftn.nul-unsafe">1</a>]</sup>. </td></tr><tr><td><span class="term"><em class="parameter"><code>to_codeset</code></em> :</span></td><td> name of character set into which to convert <em class="parameter"><code>str</code></em></td></tr><tr><td><span class="term"><em class="parameter"><code>from_codeset</code></em> :</span></td><td> character set of <em class="parameter"><code>str</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>fallback</code></em> :</span></td><td> UTF-8 string to use in place of character not present in the target encoding. (The string must be representable in the target encoding). If <code class="literal">NULL</code>, characters not in the target encoding will be represented as Unicode escapes \uxxxx or \Uxxxxyyyy.</td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_read</code></em> :</span></td><td> location to store the number of bytes in the input string that were successfully converted, or <code class="literal">NULL</code>. 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.</td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_written</code></em> :</span></td><td> the number of bytes stored in the output buffer (not including the terminating nul).</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> location to store the error occuring, or <code class="literal">NULL</code> to ignore errors. Any of the errors in <a href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> may occur.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> If the conversion was successful, a newly allocated nul-terminated string, which must be freed with <a href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>. Otherwise <code class="literal">NULL</code> 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="id2962205"></a><h3><a name="GIConv"></a>GIConv</h3><a class="indexterm" name="id2962215"></a><pre class="programlisting">typedef struct _GIConv GIConv;</pre><p>The <span class="structname">GIConv</span> struct wraps an<code class="function"><code class="function">iconv()</code></code> conversion descriptor. It contains private dataand should only be accessed using the following functions.</p></div><hr><div class="refsect2" lang="en"><a name="id2962250"></a><h3><a name="g-convert-with-iconv"></a>g_convert_with_iconv ()</h3><a class="indexterm" name="id2962261"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_convert_with_iconv (const <a href="glib-Basic-Types.html#gchar">gchar</a> *str, <a href="glib-Basic-Types.html#gssize">gssize</a> len, <a href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> converter, <a href="glib-Basic-Types.html#gsize">gsize</a> *bytes_read, <a href="glib-Basic-Types.html#gsize">gsize</a> *bytes_written, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts a string from one character set to another.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>str</code></em> :</span></td><td> the string to convert</td></tr><tr><td><span class="term"><em class="parameter"><code>len</code></em> :</span></td><td> the length of the string, or -1 if the string is nul-terminated<sup>[<a href="#ftn.nul-unsafe">1</a>]</sup>. </td></tr><tr><td><span class="term"><em class="parameter"><code>converter</code></em> :</span></td><td> conversion descriptor from <a href="glib-Character-Set-Conversion.html#g-iconv-open"><code class="function">g_iconv_open()</code></a></td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_read</code></em> :</span></td><td> location to store the number of bytes in the input string that were successfully converted, or <code class="literal">NULL</code>. 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 <span class="type">G_CONVERT_ERROR_ILLEGAL_SEQUENCE</span> occurs, the value stored will the byte offset after the last valid input sequence.</td></tr><tr><td><span class="term"><em class="parameter"><code>bytes_written</code></em> :</span></td><td> the number of bytes stored in the output buffer (not including the terminating nul).</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> location to store the error occuring, or <code class="literal">NULL</code> to ignore errors. Any of the errors in <a href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> may occur.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> If the conversion was successful, a newly allocated nul-terminated string, which must be freed with <a href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>. Otherwise <code class="literal">NULL</code> 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="id2962518"></a><h3><a name="G-CONVERT-ERROR:CAPS"></a>G_CONVERT_ERROR</h3><a class="indexterm" name="id2962529"></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 href="glib-Character-Set-Conversion.html#GConvertError"><span class="type">GConvertError</span></a> enumeration. See <a 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="id2962562"></a><h3><a name="g-iconv-open"></a>g_iconv_open ()</h3><a class="indexterm" name="id2962573"></a><pre class="programlisting"><a href="glib-Character-Set-Conversion.html#GIConv">GIConv</a> g_iconv_open (const <a href="glib-Basic-Types.html#gchar">gchar</a> *to_codeset, const <a 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 lack
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -