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