Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-21 09:54:07

0001 /* GLIB - Library of useful routines for C programming
0002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 /*
0021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
0022  * file for a list of people on the GLib Team.  See the ChangeLog
0023  * files for a list of changes.  These files are distributed with
0024  * GLib at ftp://ftp.gtk.org/pub/gtk/.
0025  */
0026 
0027 #ifndef __G_STRING_H__
0028 #define __G_STRING_H__
0029 
0030 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0031 #error "Only <glib.h> can be included directly."
0032 #endif
0033 
0034 #include <glib/gtypes.h>
0035 #include <glib/gunicode.h>
0036 #include <glib/gbytes.h>
0037 #include <glib/gstrfuncs.h>
0038 #include <glib/gutils.h>  /* for G_CAN_INLINE */
0039 #include <string.h>
0040 
0041 G_BEGIN_DECLS
0042 
0043 typedef struct _GString         GString;
0044 
0045 struct _GString
0046 {
0047   gchar  *str;
0048   gsize len;
0049   gsize allocated_len;
0050 };
0051 
0052 GLIB_AVAILABLE_IN_ALL
0053 GString*     g_string_new               (const gchar     *init);
0054 GLIB_AVAILABLE_IN_2_78
0055 GString*     g_string_new_take          (gchar           *init);
0056 GLIB_AVAILABLE_IN_ALL
0057 GString*     g_string_new_len           (const gchar     *init,
0058                                          gssize           len);
0059 GLIB_AVAILABLE_IN_ALL
0060 GString*     g_string_sized_new         (gsize            dfl_size);
0061 GLIB_AVAILABLE_IN_ALL
0062 gchar*      (g_string_free)             (GString         *string,
0063                                          gboolean         free_segment);
0064 GLIB_AVAILABLE_IN_2_76
0065 gchar*       g_string_free_and_steal    (GString         *string) G_GNUC_WARN_UNUSED_RESULT;
0066 
0067 #if G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76)
0068 
0069 #if !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3)
0070 
0071 #define g_string_free(str, free_segment)        \
0072   (__builtin_constant_p (free_segment) ?        \
0073     ((free_segment) ?                           \
0074       (g_string_free) ((str), (free_segment)) : \
0075       g_string_free_and_steal (str))            \
0076     :                                           \
0077     (g_string_free) ((str), (free_segment)))
0078 
0079 #endif /* !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3) */
0080 
0081 #endif /* G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76) */
0082 
0083 GLIB_AVAILABLE_IN_2_34
0084 GBytes*      g_string_free_to_bytes     (GString         *string);
0085 GLIB_AVAILABLE_IN_ALL
0086 gboolean     g_string_equal             (const GString   *v,
0087                                          const GString   *v2);
0088 GLIB_AVAILABLE_IN_ALL
0089 guint        g_string_hash              (const GString   *str);
0090 GLIB_AVAILABLE_IN_ALL
0091 GString*     g_string_assign            (GString         *string,
0092                                          const gchar     *rval);
0093 GLIB_AVAILABLE_IN_ALL
0094 GString*     g_string_truncate          (GString         *string,
0095                                          gsize            len);
0096 GLIB_AVAILABLE_IN_ALL
0097 GString*     g_string_set_size          (GString         *string,
0098                                          gsize            len);
0099 GLIB_AVAILABLE_IN_ALL
0100 GString*     g_string_insert_len        (GString         *string,
0101                                          gssize           pos,
0102                                          const gchar     *val,
0103                                          gssize           len);
0104 GLIB_AVAILABLE_IN_ALL
0105 GString*     g_string_append            (GString         *string,
0106                                          const gchar     *val);
0107 GLIB_AVAILABLE_IN_ALL
0108 GString*     g_string_append_len        (GString         *string,
0109                                          const gchar     *val,
0110                                          gssize           len);
0111 GLIB_AVAILABLE_IN_ALL
0112 GString*     g_string_append_c          (GString         *string,
0113                                          gchar            c);
0114 GLIB_AVAILABLE_IN_ALL
0115 GString*     g_string_append_unichar    (GString         *string,
0116                                          gunichar         wc);
0117 GLIB_AVAILABLE_IN_ALL
0118 GString*     g_string_prepend           (GString         *string,
0119                                          const gchar     *val);
0120 GLIB_AVAILABLE_IN_ALL
0121 GString*     g_string_prepend_c         (GString         *string,
0122                                          gchar            c);
0123 GLIB_AVAILABLE_IN_ALL
0124 GString*     g_string_prepend_unichar   (GString         *string,
0125                                          gunichar         wc);
0126 GLIB_AVAILABLE_IN_ALL
0127 GString*     g_string_prepend_len       (GString         *string,
0128                                          const gchar     *val,
0129                                          gssize           len);
0130 GLIB_AVAILABLE_IN_ALL
0131 GString*     g_string_insert            (GString         *string,
0132                                          gssize           pos,
0133                                          const gchar     *val);
0134 GLIB_AVAILABLE_IN_ALL
0135 GString*     g_string_insert_c          (GString         *string,
0136                                          gssize           pos,
0137                                          gchar            c);
0138 GLIB_AVAILABLE_IN_ALL
0139 GString*     g_string_insert_unichar    (GString         *string,
0140                                          gssize           pos,
0141                                          gunichar         wc);
0142 GLIB_AVAILABLE_IN_ALL
0143 GString*     g_string_overwrite         (GString         *string,
0144                                          gsize            pos,
0145                                          const gchar     *val);
0146 GLIB_AVAILABLE_IN_ALL
0147 GString*     g_string_overwrite_len     (GString         *string,
0148                                          gsize            pos,
0149                                          const gchar     *val,
0150                                          gssize           len);
0151 GLIB_AVAILABLE_IN_ALL
0152 GString*     g_string_erase             (GString         *string,
0153                                          gssize           pos,
0154                                          gssize           len);
0155 GLIB_AVAILABLE_IN_2_68
0156 guint         g_string_replace          (GString         *string,
0157                                          const gchar     *find,
0158                                          const gchar     *replace,
0159                                          guint            limit);
0160 GLIB_AVAILABLE_IN_ALL
0161 GString*     g_string_ascii_down        (GString         *string);
0162 GLIB_AVAILABLE_IN_ALL
0163 GString*     g_string_ascii_up          (GString         *string);
0164 GLIB_AVAILABLE_IN_ALL
0165 void         g_string_vprintf           (GString         *string,
0166                                          const gchar     *format,
0167                                          va_list          args)
0168                                          G_GNUC_PRINTF(2, 0);
0169 GLIB_AVAILABLE_IN_ALL
0170 void         g_string_printf            (GString         *string,
0171                                          const gchar     *format,
0172                                          ...) G_GNUC_PRINTF (2, 3);
0173 GLIB_AVAILABLE_IN_ALL
0174 void         g_string_append_vprintf    (GString         *string,
0175                                          const gchar     *format,
0176                                          va_list          args)
0177                                          G_GNUC_PRINTF(2, 0);
0178 GLIB_AVAILABLE_IN_ALL
0179 void         g_string_append_printf     (GString         *string,
0180                                          const gchar     *format,
0181                                          ...) G_GNUC_PRINTF (2, 3);
0182 GLIB_AVAILABLE_IN_ALL
0183 GString*     g_string_append_uri_escaped (GString         *string,
0184                                           const gchar     *unescaped,
0185                                           const gchar     *reserved_chars_allowed,
0186                                           gboolean         allow_utf8);
0187 
0188 #ifdef G_CAN_INLINE
0189 
0190 #if defined (_MSC_VER) && !defined (__clang__)
0191 #pragma warning (push)
0192 #pragma warning (disable : 4141) /* silence "warning C4141: 'inline' used more than once" */
0193 #endif
0194 
0195 #ifndef __GTK_DOC_IGNORE__
0196 
0197 G_ALWAYS_INLINE
0198 static inline GString*
0199 g_string_append_c_inline (GString *gstring,
0200                           gchar    c)
0201 {
0202   if (G_LIKELY (gstring != NULL &&
0203                 gstring->len + 1 < gstring->allocated_len))
0204     {
0205       gstring->str[gstring->len++] = c;
0206       gstring->str[gstring->len] = 0;
0207     }
0208   else
0209     g_string_insert_c (gstring, -1, c);
0210   return gstring;
0211 }
0212 
0213 #define g_string_append_c(gstr,c) \
0214   g_string_append_c_inline (gstr, c)
0215 
0216 G_ALWAYS_INLINE
0217 static inline GString *
0218 g_string_append_len_inline (GString    *gstring,
0219                             const char *val,
0220                             gssize      len)
0221 {
0222   gsize len_unsigned;
0223 
0224   if G_UNLIKELY (gstring == NULL)
0225     return g_string_append_len (gstring, val, len);
0226 
0227   if G_UNLIKELY (val == NULL)
0228     return (len != 0) ? g_string_append_len (gstring, val, len) : gstring;
0229 
0230   if (len < 0)
0231     len_unsigned = strlen (val);
0232   else
0233     len_unsigned = (gsize) len;
0234 
0235   if (G_LIKELY (gstring->len + len_unsigned < gstring->allocated_len))
0236     {
0237       char *end = gstring->str + gstring->len;
0238       if (G_LIKELY (val + len_unsigned <= end || val > end + len_unsigned))
0239         memcpy (end, val, len_unsigned);
0240       else
0241         memmove (end, val, len_unsigned);
0242       gstring->len += len_unsigned;
0243       gstring->str[gstring->len] = 0;
0244       return gstring;
0245     }
0246   else
0247     return g_string_insert_len (gstring, -1, val, len);
0248 }
0249 
0250 #define g_string_append_len(gstr, val, len) \
0251   g_string_append_len_inline (gstr, val, len)
0252 
0253 G_ALWAYS_INLINE
0254 static inline GString *
0255 g_string_truncate_inline (GString *gstring,
0256                           gsize    len)
0257 {
0258   gstring->len = MIN (len, gstring->len);
0259   gstring->str[gstring->len] = '\0';
0260   return gstring;
0261 }
0262 
0263 #define g_string_truncate(gstr, len) \
0264   g_string_truncate_inline (gstr, len)
0265 
0266 #if G_GNUC_CHECK_VERSION (2, 0)
0267 
0268 #define g_string_append(gstr, val)                  \
0269   (__builtin_constant_p (val) ?                     \
0270     G_GNUC_EXTENSION ({                             \
0271       const char * const __val = (val);             \
0272       g_string_append_len (gstr, __val,             \
0273         G_LIKELY (__val != NULL) ?                  \
0274           (gssize) strlen (_G_STR_NONNULL (__val))  \
0275         : (gssize) -1);                             \
0276     })                                              \
0277     :                                               \
0278     g_string_append_len (gstr, val, (gssize) -1))
0279 
0280 #endif /* G_GNUC_CHECK_VERSION (2, 0) */
0281 
0282 #endif /* __GTK_DOC_IGNORE__ */
0283 
0284 #if defined (_MSC_VER) && !defined (__clang__)
0285 #pragma warning (pop) /* #pragma warning (disable : 4141) */
0286 #endif
0287 
0288 #endif /* G_CAN_INLINE */
0289 
0290 GLIB_DEPRECATED
0291 GString *g_string_down (GString *string);
0292 GLIB_DEPRECATED
0293 GString *g_string_up   (GString *string);
0294 
0295 #define  g_string_sprintf  g_string_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_printf)
0296 #define  g_string_sprintfa g_string_append_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_append_printf)
0297 
0298 G_END_DECLS
0299 
0300 #endif /* __G_STRING_H__ */