(mc_g_string_copy): new API that extends GString one.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-11-16 19:33:26 +03:00
parent 0acac06158
commit 01f096f52f
2 changed files with 29 additions and 0 deletions

View File

@ -160,3 +160,29 @@ g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */ #endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* mc_g_string_copy:
* @dest: (not nullable): the destination #GString. Its current contents are destroyed
* @src: (not nullable): the source #GString
* @return: @dest
*
* Copies the bytes from a #GString into a #GString, destroying any previous contents.
* It is rather like the standard strcpy() function, except that you do not have to worry about
* having enough space to copy the string.
*
* There is no such API in GLib2.
*/
GString *
mc_g_string_copy (GString * dest, const GString * src)
{
g_return_val_if_fail (src != NULL, NULL);
g_return_val_if_fail (dest != NULL, NULL);
g_string_set_size (dest, 0);
g_string_append_len (dest, src->str, src->len);
return dest;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -24,6 +24,9 @@ void g_queue_free_full (GQueue * queue, GDestroyNotify free_func);
void g_queue_clear_full (GQueue * queue, GDestroyNotify free_func); void g_queue_clear_full (GQueue * queue, GDestroyNotify free_func);
#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */ #endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
/* There is no such API in GLib2 */
GString *mc_g_string_copy (GString * dest, const GString * src);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC_GLIBCOMPAT_H */ #endif /* MC_GLIBCOMPAT_H */