1/* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#ifndef __G_STRING_H__
26#define __G_STRING_H__
27
28#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29#error "Only <glib.h> can be included directly."
30#endif
31
32#include <glib/gtypes.h>
33#include <glib/gunicode.h>
34#include <glib/gbytes.h>
35#include <glib/gutils.h> /* for G_CAN_INLINE */
36
37G_BEGIN_DECLS
38
39typedef struct _GString GString;
40
41struct _GString
42{
43 gchar *str;
44 gsize len;
45 gsize allocated_len;
46};
47
48GLIB_AVAILABLE_IN_ALL
49GString* g_string_new (const gchar *init);
50GLIB_AVAILABLE_IN_ALL
51GString* g_string_new_len (const gchar *init,
52 gssize len);
53GLIB_AVAILABLE_IN_ALL
54GString* g_string_sized_new (gsize dfl_size);
55GLIB_AVAILABLE_IN_ALL
56gchar* g_string_free (GString *string,
57 gboolean free_segment);
58GLIB_AVAILABLE_IN_2_34
59GBytes* g_string_free_to_bytes (GString *string);
60GLIB_AVAILABLE_IN_ALL
61gboolean g_string_equal (const GString *v,
62 const GString *v2);
63GLIB_AVAILABLE_IN_ALL
64guint g_string_hash (const GString *str);
65GLIB_AVAILABLE_IN_ALL
66GString* g_string_assign (GString *string,
67 const gchar *rval);
68GLIB_AVAILABLE_IN_ALL
69GString* g_string_truncate (GString *string,
70 gsize len);
71GLIB_AVAILABLE_IN_ALL
72GString* g_string_set_size (GString *string,
73 gsize len);
74GLIB_AVAILABLE_IN_ALL
75GString* g_string_insert_len (GString *string,
76 gssize pos,
77 const gchar *val,
78 gssize len);
79GLIB_AVAILABLE_IN_ALL
80GString* g_string_append (GString *string,
81 const gchar *val);
82GLIB_AVAILABLE_IN_ALL
83GString* g_string_append_len (GString *string,
84 const gchar *val,
85 gssize len);
86GLIB_AVAILABLE_IN_ALL
87GString* g_string_append_c (GString *string,
88 gchar c);
89GLIB_AVAILABLE_IN_ALL
90GString* g_string_append_unichar (GString *string,
91 gunichar wc);
92GLIB_AVAILABLE_IN_ALL
93GString* g_string_prepend (GString *string,
94 const gchar *val);
95GLIB_AVAILABLE_IN_ALL
96GString* g_string_prepend_c (GString *string,
97 gchar c);
98GLIB_AVAILABLE_IN_ALL
99GString* g_string_prepend_unichar (GString *string,
100 gunichar wc);
101GLIB_AVAILABLE_IN_ALL
102GString* g_string_prepend_len (GString *string,
103 const gchar *val,
104 gssize len);
105GLIB_AVAILABLE_IN_ALL
106GString* g_string_insert (GString *string,
107 gssize pos,
108 const gchar *val);
109GLIB_AVAILABLE_IN_ALL
110GString* g_string_insert_c (GString *string,
111 gssize pos,
112 gchar c);
113GLIB_AVAILABLE_IN_ALL
114GString* g_string_insert_unichar (GString *string,
115 gssize pos,
116 gunichar wc);
117GLIB_AVAILABLE_IN_ALL
118GString* g_string_overwrite (GString *string,
119 gsize pos,
120 const gchar *val);
121GLIB_AVAILABLE_IN_ALL
122GString* g_string_overwrite_len (GString *string,
123 gsize pos,
124 const gchar *val,
125 gssize len);
126GLIB_AVAILABLE_IN_ALL
127GString* g_string_erase (GString *string,
128 gssize pos,
129 gssize len);
130GLIB_AVAILABLE_IN_2_68
131guint g_string_replace (GString *string,
132 const gchar *find,
133 const gchar *replace,
134 guint limit);
135GLIB_AVAILABLE_IN_ALL
136GString* g_string_ascii_down (GString *string);
137GLIB_AVAILABLE_IN_ALL
138GString* g_string_ascii_up (GString *string);
139GLIB_AVAILABLE_IN_ALL
140void g_string_vprintf (GString *string,
141 const gchar *format,
142 va_list args)
143 G_GNUC_PRINTF(2, 0);
144GLIB_AVAILABLE_IN_ALL
145void g_string_printf (GString *string,
146 const gchar *format,
147 ...) G_GNUC_PRINTF (2, 3);
148GLIB_AVAILABLE_IN_ALL
149void g_string_append_vprintf (GString *string,
150 const gchar *format,
151 va_list args)
152 G_GNUC_PRINTF(2, 0);
153GLIB_AVAILABLE_IN_ALL
154void g_string_append_printf (GString *string,
155 const gchar *format,
156 ...) G_GNUC_PRINTF (2, 3);
157GLIB_AVAILABLE_IN_ALL
158GString* g_string_append_uri_escaped (GString *string,
159 const gchar *unescaped,
160 const gchar *reserved_chars_allowed,
161 gboolean allow_utf8);
162
163/* -- optimize g_strig_append_c --- */
164#ifdef G_CAN_INLINE
165static inline GString*
166g_string_append_c_inline (GString *gstring,
167 gchar c)
168{
169 if (gstring->len + 1 < gstring->allocated_len)
170 {
171 gstring->str[gstring->len++] = c;
172 gstring->str[gstring->len] = 0;
173 }
174 else
175 g_string_insert_c (string: gstring, pos: -1, c);
176 return gstring;
177}
178#define g_string_append_c(gstr,c) g_string_append_c_inline (gstr, c)
179#endif /* G_CAN_INLINE */
180
181
182GLIB_DEPRECATED
183GString *g_string_down (GString *string);
184GLIB_DEPRECATED
185GString *g_string_up (GString *string);
186
187#define g_string_sprintf g_string_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_printf)
188#define g_string_sprintfa g_string_append_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_append_printf)
189
190G_END_DECLS
191
192#endif /* __G_STRING_H__ */
193

source code of include/glib-2.0/glib/gstring.h