GVariant: fix some refcounting issues
[platform/upstream/glib.git] / glib / gstring.h
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 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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
30
31 #ifndef __G_STRING_H__
32 #define __G_STRING_H__
33
34 #include <glib/gtypes.h>
35 #include <glib/gunicode.h>
36 #include <glib/gutils.h>  /* for G_CAN_INLINE */
37
38 G_BEGIN_DECLS
39
40 typedef struct _GString         GString;
41 typedef struct _GStringChunk    GStringChunk;
42
43 struct _GString
44 {
45   gchar  *str;
46   gsize len;    
47   gsize allocated_len;
48 };
49
50 /* String Chunks
51  */
52 GStringChunk* g_string_chunk_new           (gsize size);  
53 void          g_string_chunk_free          (GStringChunk *chunk);
54 void          g_string_chunk_clear         (GStringChunk *chunk);
55 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
56                                             const gchar  *string);
57 gchar*        g_string_chunk_insert_len    (GStringChunk *chunk,
58                                             const gchar  *string,
59                                             gssize        len);
60 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
61                                             const gchar  *string);
62
63
64 /* Strings
65  */
66 GString*     g_string_new               (const gchar     *init);
67 GString*     g_string_new_len           (const gchar     *init,
68                                          gssize           len);   
69 GString*     g_string_sized_new         (gsize            dfl_size);  
70 gchar*       g_string_free              (GString         *string,
71                                          gboolean         free_segment);
72 gboolean     g_string_equal             (const GString   *v,
73                                          const GString   *v2);
74 guint        g_string_hash              (const GString   *str);
75 GString*     g_string_assign            (GString         *string,
76                                          const gchar     *rval);
77 GString*     g_string_truncate          (GString         *string,
78                                          gsize            len);    
79 GString*     g_string_set_size          (GString         *string,
80                                          gsize            len);
81 GString*     g_string_insert_len        (GString         *string,
82                                          gssize           pos,   
83                                          const gchar     *val,
84                                          gssize           len);  
85 GString*     g_string_append            (GString         *string,
86                                          const gchar     *val);
87 GString*     g_string_append_len        (GString         *string,
88                                          const gchar     *val,
89                                          gssize           len);  
90 GString*     g_string_append_c          (GString         *string,
91                                          gchar            c);
92 GString*     g_string_append_unichar    (GString         *string,
93                                          gunichar         wc);
94 GString*     g_string_prepend           (GString         *string,
95                                          const gchar     *val);
96 GString*     g_string_prepend_c         (GString         *string,
97                                          gchar            c);
98 GString*     g_string_prepend_unichar   (GString         *string,
99                                          gunichar         wc);
100 GString*     g_string_prepend_len       (GString         *string,
101                                          const gchar     *val,
102                                          gssize           len);  
103 GString*     g_string_insert            (GString         *string,
104                                          gssize           pos,    
105                                          const gchar     *val);
106 GString*     g_string_insert_c          (GString         *string,
107                                          gssize           pos,    
108                                          gchar            c);
109 GString*     g_string_insert_unichar    (GString         *string,
110                                          gssize           pos,    
111                                          gunichar         wc);
112 GString*     g_string_overwrite         (GString         *string,
113                                          gsize            pos,    
114                                          const gchar     *val);
115 GString*     g_string_overwrite_len     (GString         *string,
116                                          gsize            pos,    
117                                          const gchar     *val,
118                                          gssize           len);
119 GString*     g_string_erase             (GString         *string,
120                                          gssize           pos,
121                                          gssize           len);
122 GString*     g_string_ascii_down        (GString         *string);
123 GString*     g_string_ascii_up          (GString         *string);
124 void         g_string_vprintf           (GString         *string,
125                                          const gchar     *format,
126                                          va_list          args);
127 void         g_string_printf            (GString         *string,
128                                          const gchar     *format,
129                                          ...) G_GNUC_PRINTF (2, 3);
130 void         g_string_append_vprintf    (GString         *string,
131                                          const gchar     *format,
132                                          va_list          args);
133 void         g_string_append_printf     (GString         *string,
134                                          const gchar     *format,
135                                          ...) G_GNUC_PRINTF (2, 3);
136 GString *    g_string_append_uri_escaped(GString         *string,
137                                          const char      *unescaped,
138                                          const char      *reserved_chars_allowed,
139                                          gboolean         allow_utf8);
140
141 /* -- optimize g_strig_append_c --- */
142 #ifdef G_CAN_INLINE
143 static inline GString*
144 g_string_append_c_inline (GString *gstring,
145                           gchar    c)
146 {
147   if (gstring->len + 1 < gstring->allocated_len)
148     {
149       gstring->str[gstring->len++] = c;
150       gstring->str[gstring->len] = 0;
151     }
152   else
153     g_string_insert_c (gstring, -1, c);
154   return gstring;
155 }
156 #define g_string_append_c(gstr,c)       g_string_append_c_inline (gstr, c)
157 #endif /* G_CAN_INLINE */
158
159
160 #ifndef G_DISABLE_DEPRECATED
161
162 /* The following two functions are deprecated and will be removed in
163  * the next major release. They use the locale-specific tolower and
164  * toupper, which is almost never the right thing.
165  */
166
167 GString*     g_string_down              (GString         *string);
168 GString*     g_string_up                (GString         *string);
169
170 /* These aliases are included for compatibility. */
171 #define g_string_sprintf        g_string_printf
172 #define g_string_sprintfa       g_string_append_printf
173
174 #endif /* G_DISABLE_DEPRECATED */
175
176 G_END_DECLS
177
178 #endif /* __G_STRING_H__ */