glib-string-utility-functions.html

来自「glid编写实例」· HTML 代码 · 共 1,304 行 · 第 1/5 页

HTML
1,304 行
字号
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> a pointer to the found occurrence, or   <code class="literal">NULL</code> if not found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939933"></a><h3><a name="g-str-has-prefix"></a>g_str_has_prefix ()</h3><a class="indexterm" name="id2939944"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_str_has_prefix                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *str,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *prefix);</pre><p>Looks whether the string <em class="parameter"><code>str</code></em> begins with <em class="parameter"><code>prefix</code></em>.</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>&#160;:</span></td><td> a nul-terminated string.</td></tr><tr><td><span class="term"><em class="parameter"><code>prefix</code></em>&#160;:</span></td><td> the nul-terminated prefix to look for.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> <code class="literal">TRUE</code> if <em class="parameter"><code>str</code></em> begins with <em class="parameter"><code>prefix</code></em>, <code class="literal">FALSE</code> otherwise.</td></tr></tbody></table></div><p>Since  2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2940065"></a><h3><a name="g-str-has-suffix"></a>g_str_has_suffix ()</h3><a class="indexterm" name="id2940076"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_str_has_suffix                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *str,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *suffix);</pre><p>Looks whether the string <em class="parameter"><code>str</code></em> ends with <em class="parameter"><code>suffix</code></em>.</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>&#160;:</span></td><td> a nul-terminated string.</td></tr><tr><td><span class="term"><em class="parameter"><code>suffix</code></em>&#160;:</span></td><td> the nul-terminated suffix to look for.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> <code class="literal">TRUE</code> if <em class="parameter"><code>str</code></em> end with <em class="parameter"><code>suffix</code></em>, <code class="literal">FALSE</code> otherwise.</td></tr></tbody></table></div><p>Since  2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2940197"></a><h3><a name="g-strlcpy"></a>g_strlcpy ()</h3><a class="indexterm" name="id2940208"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gsize">gsize</a>       g_strlcpy                       (<a href="glib-Basic-Types.html#gchar">gchar</a> *dest,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *src,                                             <a href="glib-Basic-Types.html#gsize">gsize</a> dest_size);</pre><p>Portability wrapper that calls <code class="function">strlcpy()</code> on systems which have it, and emulates<code class="function">strlcpy()</code> otherwise. Copies <em class="parameter"><code>src</code></em> to <em class="parameter"><code>dest</code></em>; <em class="parameter"><code>dest</code></em> is guaranteed to benul-terminated; <em class="parameter"><code>src</code></em> must be nul-terminated; <em class="parameter"><code>dest_size</code></em> is the buffer size, notthe number of chars to copy. Caveat: <code class="function">strlcpy()</code> is supposedly more secure than<code class="function">strcpy()</code> or <code class="function">strncpy()</code>, but if you really want to avoid screwups, <a href="glib-String-Utility-Functions.html#g-strdup"><code class="function">g_strdup()</code></a> isan even better idea.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dest</code></em>&#160;:</span></td><td>destination buffer</td></tr><tr><td><span class="term"><em class="parameter"><code>src</code></em>&#160;:</span></td><td>source buffer</td></tr><tr><td><span class="term"><em class="parameter"><code>dest_size</code></em>&#160;:</span></td><td>length of <em class="parameter"><code>dest</code></em> in bytes</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>length of <em class="parameter"><code>src</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2940418"></a><h3><a name="g-strlcat"></a>g_strlcat ()</h3><a class="indexterm" name="id2940429"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gsize">gsize</a>       g_strlcat                       (<a href="glib-Basic-Types.html#gchar">gchar</a> *dest,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *src,                                             <a href="glib-Basic-Types.html#gsize">gsize</a> dest_size);</pre><p>Portability wrapper that calls <code class="function">strlcat()</code> on systems which have it, and emulates it otherwise. Appends nul-terminated <em class="parameter"><code>src</code></em> string to <em class="parameter"><code>dest</code></em>, guaranteeingnul-termination for <em class="parameter"><code>dest</code></em>. The total size of <em class="parameter"><code>dest</code></em> won't exceed<em class="parameter"><code>dest_size</code></em>. Caveat: this is supposedly a more secure alternative to <code class="function">strcat()</code> or<code class="function">strncat()</code>, but for real security <a href="glib-String-Utility-Functions.html#g-strconcat"><code class="function">g_strconcat()</code></a> is harder to mess up.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dest</code></em>&#160;:</span></td><td>destination buffer, already containing one nul-terminated string</td></tr><tr><td><span class="term"><em class="parameter"><code>src</code></em>&#160;:</span></td><td>source buffer</td></tr><tr><td><span class="term"><em class="parameter"><code>dest_size</code></em>&#160;:</span></td><td>length of <em class="parameter"><code>dest</code></em> buffer in bytes (not length of existing string inside <em class="parameter"><code>dest</code></em>)</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>length of <em class="parameter"><code>src</code></em> plus initial length of string in <em class="parameter"><code>dest</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2940633"></a><h3><a name="g-strdup-printf"></a>g_strdup_printf ()</h3><a class="indexterm" name="id2940643"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strdup_printf                 (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format,                                             ...);</pre><p>Similar to the standard C <code class="function">sprintf()</code> functionbut safer, since it calculates the maximum space required and allocatesmemory to hold the result.The returned string should be freed when no longer needed.</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>&#160;:</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>&#160;:</span></td><td>the parameters to insert into the format string.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a newly-allocated string holding the result.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2940750"></a><h3><a name="g-strdup-vprintf"></a>g_strdup_vprintf ()</h3><a class="indexterm" name="id2940760"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strdup_vprintf                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format,                                             va_list args);</pre><p>Similar to the standard C <code class="function">vsprintf()</code> functionbut safer, since it calculates the maximum space required and allocatesmemory to hold the result.The returned string should be freed when no longer needed.</p><p>See also <a href="glib-String-Utility-Functions.html#g-vasprintf"><code class="function">g_vasprintf()</code></a>, which offers the same functionality, but additionallyreturns the length of the allocated string. </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>&#160;:</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>&#160;:</span></td><td>the list of parameters to insert into the format string.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a newly-allocated string holding the result.</td></tr></tbody>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?