1/* grefstring.h: Reference counted strings
2 *
3 * Copyright 2018 Emmanuele Bassi
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "gmem.h"
22#include "gmacros.h"
23
24G_BEGIN_DECLS
25
26GLIB_AVAILABLE_IN_2_58
27char * g_ref_string_new (const char *str);
28GLIB_AVAILABLE_IN_2_58
29char * g_ref_string_new_len (const char *str,
30 gssize len);
31GLIB_AVAILABLE_IN_2_58
32char * g_ref_string_new_intern (const char *str);
33
34GLIB_AVAILABLE_IN_2_58
35char * g_ref_string_acquire (char *str);
36GLIB_AVAILABLE_IN_2_58
37void g_ref_string_release (char *str);
38
39GLIB_AVAILABLE_IN_2_58
40gsize g_ref_string_length (char *str);
41
42/**
43 * GRefString:
44 *
45 * A typedef for a reference-counted string. A pointer to a #GRefString can be
46 * treated like a standard `char*` array by all code, but can additionally have
47 * `g_ref_string_*()` methods called on it. `g_ref_string_*()` methods cannot be
48 * called on `char*` arrays not allocated using g_ref_string_new().
49 *
50 * If using #GRefString with autocleanups, g_autoptr() must be used rather than
51 * g_autofree(), so that the reference counting metadata is also freed.
52 *
53 * Since: 2.58
54 */
55typedef char GRefString;
56
57G_END_DECLS
58