Coverage Report

Created: 2025-01-28 06:43

/usr/local/include/glib-2.0/glib/gstring.h
Line
Count
Source (jump to first uncovered line)
1
/* GLIB - Library of useful routines for C programming
2
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/*
21
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22
 * file for a list of people on the GLib Team.  See the ChangeLog
23
 * files for a list of changes.  These files are distributed with
24
 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25
 */
26
27
#ifndef __G_STRING_H__
28
#define __G_STRING_H__
29
30
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31
#error "Only <glib.h> can be included directly."
32
#endif
33
34
#include <glib/gtypes.h>
35
#include <glib/gunicode.h>
36
#include <glib/gbytes.h>
37
#include <glib/gstrfuncs.h>
38
#include <glib/gutils.h>  /* for G_CAN_INLINE */
39
#include <string.h>
40
41
G_BEGIN_DECLS
42
43
typedef struct _GString         GString;
44
45
struct _GString
46
{
47
  gchar  *str;
48
  gsize len;
49
  gsize allocated_len;
50
};
51
52
GLIB_AVAILABLE_IN_ALL
53
GString*     g_string_new               (const gchar     *init);
54
GLIB_AVAILABLE_IN_2_78
55
GString*     g_string_new_take          (gchar           *init);
56
GLIB_AVAILABLE_IN_ALL
57
GString*     g_string_new_len           (const gchar     *init,
58
                                         gssize           len);
59
GLIB_AVAILABLE_IN_ALL
60
GString*     g_string_sized_new         (gsize            dfl_size);
61
GLIB_AVAILABLE_IN_ALL
62
gchar*      (g_string_free)             (GString         *string,
63
                                         gboolean         free_segment);
64
GLIB_AVAILABLE_IN_2_76
65
gchar*       g_string_free_and_steal    (GString         *string) G_GNUC_WARN_UNUSED_RESULT;
66
67
#if G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76)
68
69
#if !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3)
70
71
#define g_string_free(str, free_segment)        \
72
  (__builtin_constant_p (free_segment) ?        \
73
    ((free_segment) ?                           \
74
      (g_string_free) ((str), (free_segment)) : \
75
      g_string_free_and_steal (str))            \
76
    :                                           \
77
    (g_string_free) ((str), (free_segment)))
78
79
#endif /* !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3) */
80
81
#endif /* G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76) */
82
83
GLIB_AVAILABLE_IN_2_34
84
GBytes*      g_string_free_to_bytes     (GString         *string);
85
GLIB_AVAILABLE_IN_ALL
86
gboolean     g_string_equal             (const GString   *v,
87
                                         const GString   *v2);
88
GLIB_AVAILABLE_IN_ALL
89
guint        g_string_hash              (const GString   *str);
90
GLIB_AVAILABLE_IN_ALL
91
GString*     g_string_assign            (GString         *string,
92
                                         const gchar     *rval);
93
GLIB_AVAILABLE_IN_ALL
94
GString*     g_string_truncate          (GString         *string,
95
                                         gsize            len);
96
GLIB_AVAILABLE_IN_ALL
97
GString*     g_string_set_size          (GString         *string,
98
                                         gsize            len);
99
GLIB_AVAILABLE_IN_ALL
100
GString*     g_string_insert_len        (GString         *string,
101
                                         gssize           pos,
102
                                         const gchar     *val,
103
                                         gssize           len);
104
GLIB_AVAILABLE_IN_ALL
105
GString*     g_string_append            (GString         *string,
106
                                         const gchar     *val);
107
GLIB_AVAILABLE_IN_ALL
108
GString*     g_string_append_len        (GString         *string,
109
                                         const gchar     *val,
110
                                         gssize           len);
111
GLIB_AVAILABLE_IN_ALL
112
GString*     g_string_append_c          (GString         *string,
113
                                         gchar            c);
114
GLIB_AVAILABLE_IN_ALL
115
GString*     g_string_append_unichar    (GString         *string,
116
                                         gunichar         wc);
117
GLIB_AVAILABLE_IN_ALL
118
GString*     g_string_prepend           (GString         *string,
119
                                         const gchar     *val);
120
GLIB_AVAILABLE_IN_ALL
121
GString*     g_string_prepend_c         (GString         *string,
122
                                         gchar            c);
123
GLIB_AVAILABLE_IN_ALL
124
GString*     g_string_prepend_unichar   (GString         *string,
125
                                         gunichar         wc);
126
GLIB_AVAILABLE_IN_ALL
127
GString*     g_string_prepend_len       (GString         *string,
128
                                         const gchar     *val,
129
                                         gssize           len);
130
GLIB_AVAILABLE_IN_ALL
131
GString*     g_string_insert            (GString         *string,
132
                                         gssize           pos,
133
                                         const gchar     *val);
134
GLIB_AVAILABLE_IN_ALL
135
GString*     g_string_insert_c          (GString         *string,
136
                                         gssize           pos,
137
                                         gchar            c);
138
GLIB_AVAILABLE_IN_ALL
139
GString*     g_string_insert_unichar    (GString         *string,
140
                                         gssize           pos,
141
                                         gunichar         wc);
142
GLIB_AVAILABLE_IN_ALL
143
GString*     g_string_overwrite         (GString         *string,
144
                                         gsize            pos,
145
                                         const gchar     *val);
146
GLIB_AVAILABLE_IN_ALL
147
GString*     g_string_overwrite_len     (GString         *string,
148
                                         gsize            pos,
149
                                         const gchar     *val,
150
                                         gssize           len);
151
GLIB_AVAILABLE_IN_ALL
152
GString*     g_string_erase             (GString         *string,
153
                                         gssize           pos,
154
                                         gssize           len);
155
GLIB_AVAILABLE_IN_2_68
156
guint         g_string_replace          (GString         *string,
157
                                         const gchar     *find,
158
                                         const gchar     *replace,
159
                                         guint            limit);
160
GLIB_AVAILABLE_IN_ALL
161
GString*     g_string_ascii_down        (GString         *string);
162
GLIB_AVAILABLE_IN_ALL
163
GString*     g_string_ascii_up          (GString         *string);
164
GLIB_AVAILABLE_IN_ALL
165
void         g_string_vprintf           (GString         *string,
166
                                         const gchar     *format,
167
                                         va_list          args)
168
                                         G_GNUC_PRINTF(2, 0);
169
GLIB_AVAILABLE_IN_ALL
170
void         g_string_printf            (GString         *string,
171
                                         const gchar     *format,
172
                                         ...) G_GNUC_PRINTF (2, 3);
173
GLIB_AVAILABLE_IN_ALL
174
void         g_string_append_vprintf    (GString         *string,
175
                                         const gchar     *format,
176
                                         va_list          args)
177
                                         G_GNUC_PRINTF(2, 0);
178
GLIB_AVAILABLE_IN_ALL
179
void         g_string_append_printf     (GString         *string,
180
                                         const gchar     *format,
181
                                         ...) G_GNUC_PRINTF (2, 3);
182
GLIB_AVAILABLE_IN_ALL
183
GString*     g_string_append_uri_escaped (GString         *string,
184
                                          const gchar     *unescaped,
185
                                          const gchar     *reserved_chars_allowed,
186
                                          gboolean         allow_utf8);
187
188
#ifdef G_CAN_INLINE
189
190
#if defined (_MSC_VER) && !defined (__clang__)
191
#pragma warning (push)
192
#pragma warning (disable : 4141) /* silence "warning C4141: 'inline' used more than once" */
193
#endif
194
195
#ifndef __GTK_DOC_IGNORE__
196
197
G_ALWAYS_INLINE
198
static inline GString*
199
g_string_append_c_inline (GString *gstring,
200
                          gchar    c)
201
0
{
202
0
  if (G_LIKELY (gstring != NULL &&
203
0
                gstring->len + 1 < gstring->allocated_len))
204
0
    {
205
0
      gstring->str[gstring->len++] = c;
206
0
      gstring->str[gstring->len] = 0;
207
0
    }
208
0
  else
209
0
    g_string_insert_c (gstring, -1, c);
210
0
  return gstring;
211
0
}
Unexecuted instantiation: gobex-apparam.c:g_string_append_c_inline
Unexecuted instantiation: gobex-defs.c:g_string_append_c_inline
Unexecuted instantiation: gobex-header.c:g_string_append_c_inline
Unexecuted instantiation: gobex-packet.c:g_string_append_c_inline
Unexecuted instantiation: gobex-transfer.c:g_string_append_c_inline
Unexecuted instantiation: gobex.c:g_string_append_c_inline
212
213
#define g_string_append_c(gstr,c) \
214
  g_string_append_c_inline (gstr, c)
215
216
G_ALWAYS_INLINE
217
static inline GString *
218
g_string_append_len_inline (GString    *gstring,
219
                            const char *val,
220
                            gssize      len)
221
0
{
222
0
  gsize len_unsigned;
223
0
224
0
  if G_UNLIKELY (gstring == NULL)
225
0
    return g_string_append_len (gstring, val, len);
226
0
227
0
  if G_UNLIKELY (val == NULL)
228
0
    return (len != 0) ? g_string_append_len (gstring, val, len) : gstring;
229
0
230
0
  if (len < 0)
231
0
    len_unsigned = strlen (val);
232
0
  else
233
0
    len_unsigned = (gsize) len;
234
0
235
0
  if (G_LIKELY (gstring->len + len_unsigned < gstring->allocated_len))
236
0
    {
237
0
      char *end = gstring->str + gstring->len;
238
0
      if (G_LIKELY (val + len_unsigned <= end || val > end + len_unsigned))
239
0
        memcpy (end, val, len_unsigned);
240
0
      else
241
0
        memmove (end, val, len_unsigned);
242
0
      gstring->len += len_unsigned;
243
0
      gstring->str[gstring->len] = 0;
244
0
      return gstring;
245
0
    }
246
0
  else
247
0
    return g_string_insert_len (gstring, -1, val, len);
248
0
}
Unexecuted instantiation: gobex-apparam.c:g_string_append_len_inline
Unexecuted instantiation: gobex-defs.c:g_string_append_len_inline
Unexecuted instantiation: gobex-header.c:g_string_append_len_inline
Unexecuted instantiation: gobex-packet.c:g_string_append_len_inline
Unexecuted instantiation: gobex-transfer.c:g_string_append_len_inline
Unexecuted instantiation: gobex.c:g_string_append_len_inline
249
250
#define g_string_append_len(gstr, val, len) \
251
  g_string_append_len_inline (gstr, val, len)
252
253
G_ALWAYS_INLINE
254
static inline GString *
255
g_string_truncate_inline (GString *gstring,
256
                          gsize    len)
257
0
{
258
0
  gstring->len = MIN (len, gstring->len);
259
0
  gstring->str[gstring->len] = '\0';
260
0
  return gstring;
261
0
}
Unexecuted instantiation: gobex-apparam.c:g_string_truncate_inline
Unexecuted instantiation: gobex-defs.c:g_string_truncate_inline
Unexecuted instantiation: gobex-header.c:g_string_truncate_inline
Unexecuted instantiation: gobex-packet.c:g_string_truncate_inline
Unexecuted instantiation: gobex-transfer.c:g_string_truncate_inline
Unexecuted instantiation: gobex.c:g_string_truncate_inline
262
263
#define g_string_truncate(gstr, len) \
264
  g_string_truncate_inline (gstr, len)
265
266
#if G_GNUC_CHECK_VERSION (2, 0)
267
268
#define g_string_append(gstr, val)                  \
269
  (__builtin_constant_p (val) ?                     \
270
    G_GNUC_EXTENSION ({                             \
271
      const char * const __val = (val);             \
272
      g_string_append_len (gstr, __val,             \
273
        G_LIKELY (__val != NULL) ?                  \
274
          (gssize) strlen (_G_STR_NONNULL (__val))  \
275
        : (gssize) -1);                             \
276
    })                                              \
277
    :                                               \
278
    g_string_append_len (gstr, val, (gssize) -1))
279
280
#endif /* G_GNUC_CHECK_VERSION (2, 0) */
281
282
#endif /* __GTK_DOC_IGNORE__ */
283
284
#if defined (_MSC_VER) && !defined (__clang__)
285
#pragma warning (pop) /* #pragma warning (disable : 4141) */
286
#endif
287
288
#endif /* G_CAN_INLINE */
289
290
GLIB_DEPRECATED
291
GString *g_string_down (GString *string);
292
GLIB_DEPRECATED
293
GString *g_string_up   (GString *string);
294
295
#define  g_string_sprintf  g_string_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_printf)
296
#define  g_string_sprintfa g_string_append_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_append_printf)
297
298
G_END_DECLS
299
300
#endif /* __G_STRING_H__ */