glib-string-utility-functions.html
来自「glid编写实例」· HTML 代码 · 共 1,304 行 · 第 1/5 页
HTML
1,304 行
<td> the number of characters printed.</td></tr></tbody></table></div><p>Since 2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2941722"></a><h3><a name="g-snprintf"></a>g_snprintf ()</h3><a class="indexterm" name="id2941732"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a> g_snprintf (<a href="glib-Basic-Types.html#gchar">gchar</a> *string, <a href="glib-Basic-Types.html#gulong">gulong</a> n, <a href="glib-Basic-Types.html#gchar">gchar</a> const *format, ...);</pre><p>A safer form of the standard <code class="function">sprintf()</code> function. The output is guaranteedto not exceed <em class="parameter"><code>n</code></em> characters (including the terminating nul character), so it is easy to ensure that a buffer overflow cannot occur.</p><p>See also <a href="glib-String-Utility-Functions.html#g-strdup-printf"><code class="function">g_strdup_printf()</code></a>.</p><p>In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be nul-terminated. In versions prior to 1.3.12, this function returns the length of the output string.</p><p>The return value of <a href="glib-String-Utility-Functions.html#g-snprintf"><code class="function">g_snprintf()</code></a> conforms to the <code class="function">snprintf()</code>function as standardized in ISO C99. Note that this is different from traditional <code class="function">snprintf()</code>, which returns the length of the output string.</p><p>The format string may contain positional parameters, as specified in the Single Unix Specification.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>string</code></em> :</span></td><td> the buffer to hold the output.</td></tr><tr><td><span class="term"><em class="parameter"><code>n</code></em> :</span></td><td> the maximum number of characters to produce (including the terminating nul character).</td></tr><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td> a standard <code class="function">printf()</code> format string, but notice <a href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>...</code></em> :</span></td><td> the arguments to insert in the output.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of characters which would be produced if the buffer was large enough.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2941954"></a><h3><a name="g-vsnprintf"></a>g_vsnprintf ()</h3><a class="indexterm" name="id2941965"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a> g_vsnprintf (<a href="glib-Basic-Types.html#gchar">gchar</a> *string, <a href="glib-Basic-Types.html#gulong">gulong</a> n, <a href="glib-Basic-Types.html#gchar">gchar</a> const *format, va_list args);</pre><p>A safer form of the standard <code class="function">vsprintf()</code> function. The output is guaranteedto not exceed <em class="parameter"><code>n</code></em> characters (including the terminating nul character), so it is easy to ensure that a buffer overflow cannot occur.</p><p>See also <a href="glib-String-Utility-Functions.html#g-strdup-vprintf"><code class="function">g_strdup_vprintf()</code></a>.</p><p>In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be nul-terminated.In versions prior to 1.3.12, this function returns the length of the output string.</p><p>The return value of <a href="glib-String-Utility-Functions.html#g-vsnprintf"><code class="function">g_vsnprintf()</code></a> conforms to the <code class="function">vsnprintf()</code> function as standardized in ISO C99. Note that this is different from traditional <code class="function">vsnprintf()</code>, which returns the length of the output string.</p><p>The format string may contain positional parameters, as specified in the Single Unix Specification.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>string</code></em> :</span></td><td> the buffer to hold the output.</td></tr><tr><td><span class="term"><em class="parameter"><code>n</code></em> :</span></td><td> the maximum number of characters to produce (including the terminating nul character).</td></tr><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td> a standard <code class="function">printf()</code> format string, but notice <a href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>args</code></em> :</span></td><td> the list of arguments to insert in the output.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of characters which would be produced if the buffer was large enough.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2942194"></a><h3><a name="g-vasprintf"></a>g_vasprintf ()</h3><a class="indexterm" name="id2942204"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a> g_vasprintf (<a href="glib-Basic-Types.html#gchar">gchar</a> **string, <a href="glib-Basic-Types.html#gchar">gchar</a> const *format, va_list args);</pre><p>An implementation of the GNU <code class="function">vasprintf()</code> function which supports positional parameters, as specified in the Single Unix Specification.This function is similar to <a href="glib-String-Utility-Functions.html#g-vsprintf"><code class="function">g_vsprintf()</code></a>, except that it allocates a string to hold the output, instead of putting the output in a buffer you allocate in advance.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>string</code></em> :</span></td><td> the return location for the newly-allocated string.</td></tr><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td> a standard <code class="function">printf()</code> format string, but notice <a href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>args</code></em> :</span></td><td> the list of arguments to insert in the output.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of characters printed.</td></tr></tbody></table></div><p>Since 2.4</p></div><hr><div class="refsect2" lang="en"><a name="id2942358"></a><h3><a name="g-printf-string-upper-bound"></a>g_printf_string_upper_bound ()</h3><a class="indexterm" name="id2942370"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gsize">gsize</a> g_printf_string_upper_bound (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format, va_list args);</pre><p>Calculates the maximum space needed to store the output of the <code class="function">sprintf()</code> function.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td>the format string. See the <code class="function">printf()</code> documentation.</td></tr><tr><td><span class="term"><em class="parameter"><code>args</code></em> :</span></td><td>the parameters to be inserted into the format string.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the maximum space needed to store the formatted string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2942471"></a><h3><a name="g-ascii-isalnum"></a>g_ascii_isalnum ()</h3><a class="indexterm" name="id2942482"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_ascii_isalnum (<a href="glib-Basic-Types.html#gchar">gchar</a> c);</pre><p>Determines whether a character is alphanumeric.</p><p>Unlike the standard C library <code class="function">isalnum()</code> function, this onlyrecognizes standard ASCII letters and ignores the locale, returning<code class="literal">FALSE</code> for all non-ASCII characters. Also unlike the standardlibrary function, this takes a <span class="type">char</span>, not an <span class="type">int</span>, so don't call it on <code class="literal">EOF</code> but no need to cast to <a href="glib-Basic-Types.html#guchar"><span class="type">guchar</span></a> before passing a possibly non-ASCII character in.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>c</code></em> :</span></td><td>any character</td>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?