Revert unintential IAPI break for g_key_file_load_from_data()
[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 (__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/gbytes.h>
37 #include <glib/gutils.h>  /* for G_CAN_INLINE */
38
39 G_BEGIN_DECLS
40
41 typedef struct _GString         GString;
42
43 struct _GString
44 {
45   gchar  *str;
46   gsize len;
47   gsize allocated_len;
48 };
49
50 GString*     g_string_new               (const gchar     *init);
51 GString*     g_string_new_len           (const gchar     *init,
52                                          gssize           len);
53 GString*     g_string_sized_new         (gsize            dfl_size);
54 gchar*       g_string_free              (GString         *string,
55                                          gboolean         free_segment);
56 GLIB_AVAILABLE_IN_2_34
57 GBytes*      g_string_free_to_bytes     (GString         *string);
58 gboolean     g_string_equal             (const GString   *v,
59                                          const GString   *v2);
60 guint        g_string_hash              (const GString   *str);
61 GString*     g_string_assign            (GString         *string,
62                                          const gchar     *rval);
63 GString*     g_string_truncate          (GString         *string,
64                                          gsize            len);
65 GString*     g_string_set_size          (GString         *string,
66                                          gsize            len);
67 GString*     g_string_insert_len        (GString         *string,
68                                          gssize           pos,
69                                          const gchar     *val,
70                                          gssize           len);
71 GString*     g_string_append            (GString         *string,
72                                          const gchar     *val);
73 GString*     g_string_append_len        (GString         *string,
74                                          const gchar     *val,
75                                          gssize           len);
76 GString*     g_string_append_c          (GString         *string,
77                                          gchar            c);
78 GString*     g_string_append_unichar    (GString         *string,
79                                          gunichar         wc);
80 GString*     g_string_prepend           (GString         *string,
81                                          const gchar     *val);
82 GString*     g_string_prepend_c         (GString         *string,
83                                          gchar            c);
84 GString*     g_string_prepend_unichar   (GString         *string,
85                                          gunichar         wc);
86 GString*     g_string_prepend_len       (GString         *string,
87                                          const gchar     *val,
88                                          gssize           len);
89 GString*     g_string_insert            (GString         *string,
90                                          gssize           pos,
91                                          const gchar     *val);
92 GString*     g_string_insert_c          (GString         *string,
93                                          gssize           pos,
94                                          gchar            c);
95 GString*     g_string_insert_unichar    (GString         *string,
96                                          gssize           pos,
97                                          gunichar         wc);
98 GString*     g_string_overwrite         (GString         *string,
99                                          gsize            pos,
100                                          const gchar     *val);
101 GString*     g_string_overwrite_len     (GString         *string,
102                                          gsize            pos,
103                                          const gchar     *val,
104                                          gssize           len);
105 GString*     g_string_erase             (GString         *string,
106                                          gssize           pos,
107                                          gssize           len);
108 GString*     g_string_ascii_down        (GString         *string);
109 GString*     g_string_ascii_up          (GString         *string);
110 void         g_string_vprintf           (GString         *string,
111                                          const gchar     *format,
112                                          va_list          args);
113 void         g_string_printf            (GString         *string,
114                                          const gchar     *format,
115                                          ...) G_GNUC_PRINTF (2, 3);
116 void         g_string_append_vprintf    (GString         *string,
117                                          const gchar     *format,
118                                          va_list          args);
119 void         g_string_append_printf     (GString         *string,
120                                          const gchar     *format,
121                                          ...) G_GNUC_PRINTF (2, 3);
122 GString*     g_string_append_uri_escaped (GString         *string,
123                                           const gchar     *unescaped,
124                                           const gchar     *reserved_chars_allowed,
125                                           gboolean         allow_utf8);
126
127 /* -- optimize g_strig_append_c --- */
128 #ifdef G_CAN_INLINE
129 static inline GString*
130 g_string_append_c_inline (GString *gstring,
131                           gchar    c)
132 {
133   if (gstring->len + 1 < gstring->allocated_len)
134     {
135       gstring->str[gstring->len++] = c;
136       gstring->str[gstring->len] = 0;
137     }
138   else
139     g_string_insert_c (gstring, -1, c);
140   return gstring;
141 }
142 #define g_string_append_c(gstr,c)       g_string_append_c_inline (gstr, c)
143 #endif /* G_CAN_INLINE */
144
145
146 GLIB_DEPRECATED
147 GString *g_string_down (GString *string);
148 GLIB_DEPRECATED
149 GString *g_string_up   (GString *string);
150
151 #ifndef G_DISABLE_DEPRECATED
152 #define  g_string_sprintf  g_string_printf
153 #define  g_string_sprintfa g_string_append_printf
154 #endif
155
156 G_END_DECLS
157
158 #endif /* __G_STRING_H__ */