diff options
Diffstat (limited to 'glib/gstring.c')
-rw-r--r-- | glib/gstring.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/glib/gstring.c b/glib/gstring.c index ad6b92231..77448f2f1 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -156,6 +156,39 @@ g_string_new (const gchar *init) } /** + * g_string_new_take: (constructor) + * @init: (nullable) (transfer full): initial text used as the string. + * Ownership of the string is transferred to the #GString. + * Passing %NULL creates an empty string. + * + * Creates a new #GString, initialized with the given string. + * + * After this call, @init belongs to the #GString and may no longer be + * modified by the caller. The memory of @data has to be dynamically + * allocated and will eventually be freed with g_free(). + * + * Returns: (transfer full): the new #GString + */ +GString * +g_string_new_take (gchar *init) +{ + GString *string; + + if (init == NULL) + { + return g_string_new (NULL); + } + + string = g_slice_new (GString); + + string->str = init; + string->len = strlen (string->str); + string->allocated_len = string->len + 1; + + return string; +} + +/** * g_string_new_len: (constructor) * @init: initial contents of the string * @len: length of @init to use |