📄 glib-character-set-conversion.html
字号:
</tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2963485"></a><h3><a name="g-filename-from-utf8"></a>g_filename_from_utf8 ()</h3><a class="indexterm" name="id2963496"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_filename_from_utf8 (const <a href="glib-Basic-Types.html#gchar">gchar</a> *utf8string, <a href="glib-Basic-Types.html#gssize">gssize</a> len, <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 UTF-8 to the encoding used for filenames.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>utf8string</code></em> :</span></td><td> a UTF-8 encoded string.</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.</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> The converted string, or <code class="literal">NULL</code> on an error.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2963697"></a><h3><a name="g-filename-from-uri"></a>g_filename_from_uri ()</h3><a class="indexterm" name="id2963708"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_filename_from_uri (const <a href="glib-Basic-Types.html#gchar">gchar</a> *uri, <a href="glib-Basic-Types.html#gchar">gchar</a> **hostname, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts an escaped ASCII-encoded URI to a local filename in theencoding used for filenames.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>uri</code></em> :</span></td><td> a uri describing a filename (escaped, encoded in ASCII).</td></tr><tr><td><span class="term"><em class="parameter"><code>hostname</code></em> :</span></td><td> Location to store hostname for the URI, or <code class="literal">NULL</code>. If there is no hostname in the URI, <code class="literal">NULL</code> will be stored in this location.</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> a newly-allocated string holding the resulting filename, or <code class="literal">NULL</code> on an error.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2963849"></a><h3><a name="g-filename-to-uri"></a>g_filename_to_uri ()</h3><a class="indexterm" name="id2963860"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_filename_to_uri (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename, const <a href="glib-Basic-Types.html#gchar">gchar</a> *hostname, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Converts an absolute filename to an escaped ASCII-encoded URI.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>filename</code></em> :</span></td><td> an absolute filename specified in the GLib file name encoding, which is the on-disk file name bytes on Unix, and UTF-8 on Windows</td></tr><tr><td><span class="term"><em class="parameter"><code>hostname</code></em> :</span></td><td> A UTF-8 encoded hostname, or <code class="literal">NULL</code> for none.</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> a newly-allocated string holding the resulting URI, or <code class="literal">NULL</code> on an error.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2963995"></a><h3><a name="g-get-filename-charsets"></a>g_get_filename_charsets ()</h3><a class="indexterm" name="id2964006"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_get_filename_charsets (G_CONST_RETURN <a href="glib-Basic-Types.html#gchar">gchar</a> ***charsets);</pre><p>Determines the preferred character sets used for filenames.The first character set from the <em class="parameter"><code>charsets</code></em> is the filename encoding, thesubsequent character sets are used when trying to generate a displayablerepresentation of a filename, see <a href="glib-Character-Set-Conversion.html#g-filename-display-name"><code class="function">g_filename_display_name()</code></a>.</p><p>On Unix, the character sets are determined by consulting theenvironment variables <code class="envar">G_FILENAME_ENCODING</code> and<code class="envar">G_BROKEN_FILENAMES</code>. On Windows, the character setused in the GLib API is always UTF-8 and said environment variableshave no effect.</p><p><code class="envar">G_FILENAME_ENCODING</code> may be set to a comma-separated list of character set names. The special token "<em class="parameter"><code>locale</code></em>" is taken to mean the character set for the current locale. If <code class="envar">G_FILENAME_ENCODING</code> is not set, but <code class="envar">G_BROKEN_FILENAMES</code> is, the character set of the current locale is taken as the filename encoding. If neither environmentvariable is set, UTF-8 is taken as the filename encoding, but the characterset of the current locale is also put in the list of encodings.</p><p>The returned <em class="parameter"><code>charsets</code></em> belong to GLib and must not be freed.</p><p>Note that on Unix, regardless of the locale character set or<code class="envar">G_FILENAME_ENCODING</code> value, the actual file names present on asystem might be in any random encoding or just gibberish.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>charsets</code></em> :</span></td><td> return location for the <code class="literal">NULL</code>-terminated list of encoding names</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> if the filename encoding is UTF-8.</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id2964166"></a><h3><a name="g-filename-display-name"></a>g_filename_display_name ()</h3><a class="indexterm" name="id2964177"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_filename_display_name (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename);</pre><p>Converts a filename into a valid UTF-8 string. The conversion is not necessarily reversible, so you should keep the original around and use the returnvalue of this function only for display purposes.Unlike <a href="glib-Character-Set-Conversion.html#g-filename-to-utf8"><code class="function">g_filename_to_utf8()</code></a>, the result is guaranteed to be non-NULL even if the filename actually isn't in the GLibfile name encoding.</p><p>If you know the whole pathname of the file you should use<a href="glib-Character-Set-Conversion.html#g-filename-display-basename"><code class="function">g_filename_display_basename()</code></a>, since that allows location-basedtranslation of filenames.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>filename</code></em> :</span></td><td> a pathname hopefully in the GLib file name encoding</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a newly allocated string containing a rendition of the filename in valid UTF-8</td></tr></tbody></table></div><p>Since 2.6</p></div><hr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -