2441213c4a94776c183d572b9ef0ff891f7e3ff8
[platform/upstream/dbus.git] / dbus / dbus-string.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-string.h String utility class (internal to D-BUS implementation)
3  * 
4  * Copyright (C) 2002, 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_STRING_H
25 #define DBUS_STRING_H
26
27 #include <config.h>
28
29 #include <dbus/dbus-memory.h>
30 #include <dbus/dbus-types.h>
31 #include <dbus/dbus-sysdeps.h>
32
33 #include <stdarg.h>
34
35 DBUS_BEGIN_DECLS;
36
37 /**
38  * DBusString object
39  */
40 struct DBusString
41 {
42   void *dummy1; /**< placeholder */
43   int   dummy2; /**< placeholder */
44   int   dummy3; /**< placeholder */
45   int   dummy4; /**< placeholder */
46   unsigned int dummy5 : 1; /**< placeholder */
47   unsigned int dummy6 : 1; /**< placeholder */
48   unsigned int dummy7 : 1; /**< placeholder */
49   unsigned int dummy8 : 3; /**< placeholder */
50 };
51
52 dbus_bool_t   _dbus_string_init                  (DBusString        *str);
53 void          _dbus_string_init_const            (DBusString        *str,
54                                                   const char        *value);
55 void          _dbus_string_init_const_len        (DBusString        *str,
56                                                   const char        *value,
57                                                   int                len);
58 dbus_bool_t   _dbus_string_init_preallocated     (DBusString        *str,
59                                                   int                allocate_size);
60 void          _dbus_string_free                  (DBusString        *str);
61 void          _dbus_string_lock                  (DBusString        *str);
62 char*         _dbus_string_get_data              (DBusString        *str);
63 const char*   _dbus_string_get_const_data        (const DBusString  *str);
64 char*         _dbus_string_get_data_len          (DBusString        *str,
65                                                   int                start,
66                                                   int                len);
67 const char*   _dbus_string_get_const_data_len    (const DBusString  *str,
68                                                   int                start,
69                                                   int                len);
70 void          _dbus_string_set_byte              (DBusString        *str,
71                                                   int                i,
72                                                   unsigned char      byte);
73 unsigned char _dbus_string_get_byte              (const DBusString  *str,
74                                                   int                start);
75 dbus_bool_t   _dbus_string_insert_bytes          (DBusString        *str,
76                                                   int                i,
77                                                   int                n_bytes,
78                                                   unsigned char      byte);
79 dbus_bool_t   _dbus_string_steal_data            (DBusString        *str,
80                                                   char             **data_return);
81 dbus_bool_t   _dbus_string_steal_data_len        (DBusString        *str,
82                                                   char             **data_return,
83                                                   int                start,
84                                                   int                len);
85 dbus_bool_t   _dbus_string_copy_data             (const DBusString  *str,
86                                                   char             **data_return);
87 dbus_bool_t   _dbus_string_copy_data_len         (const DBusString  *str,
88                                                   char             **data_return,
89                                                   int                start,
90                                                   int                len);
91 int           _dbus_string_get_length            (const DBusString  *str);
92 dbus_bool_t   _dbus_string_lengthen              (DBusString        *str,
93                                                   int                additional_length);
94 void          _dbus_string_shorten               (DBusString        *str,
95                                                   int                length_to_remove);
96 dbus_bool_t   _dbus_string_set_length            (DBusString        *str,
97                                                   int                length);
98 dbus_bool_t   _dbus_string_align_length          (DBusString        *str,
99                                                   int                alignment);
100 dbus_bool_t   _dbus_string_append                (DBusString        *str,
101                                                   const char        *buffer);
102 dbus_bool_t   _dbus_string_append_len            (DBusString        *str,
103                                                   const char        *buffer,
104                                                   int                len);
105 dbus_bool_t   _dbus_string_append_int            (DBusString        *str,
106                                                   long               value);
107 dbus_bool_t   _dbus_string_append_uint           (DBusString        *str,
108                                                   unsigned long      value);
109 dbus_bool_t   _dbus_string_append_double         (DBusString        *str,
110                                                   double             value);
111 dbus_bool_t   _dbus_string_append_byte           (DBusString        *str,
112                                                   unsigned char      byte);
113 dbus_bool_t   _dbus_string_append_unichar        (DBusString        *str,
114                                                   dbus_unichar_t     ch);
115 dbus_bool_t   _dbus_string_append_4_aligned      (DBusString        *str,
116                                                   const unsigned char octets[4]);
117 dbus_bool_t   _dbus_string_append_8_aligned      (DBusString        *str,
118                                                   const unsigned char octets[8]);
119 dbus_bool_t   _dbus_string_append_printf         (DBusString        *str,
120                                                   const char        *format,
121                                                   ...) _DBUS_GNUC_PRINTF (2, 3);
122 dbus_bool_t   _dbus_string_append_printf_valist  (DBusString        *str,
123                                                   const char        *format,
124                                                   va_list            args);
125 void          _dbus_string_delete                (DBusString        *str,
126                                                   int                start,
127                                                   int                len);
128 dbus_bool_t   _dbus_string_move                  (DBusString        *source,
129                                                   int                start,
130                                                   DBusString        *dest,
131                                                   int                insert_at);
132 dbus_bool_t   _dbus_string_copy                  (const DBusString  *source,
133                                                   int                start,
134                                                   DBusString        *dest,
135                                                   int                insert_at);
136 dbus_bool_t   _dbus_string_move_len              (DBusString        *source,
137                                                   int                start,
138                                                   int                len,
139                                                   DBusString        *dest,
140                                                   int                insert_at);
141 dbus_bool_t   _dbus_string_copy_len              (const DBusString  *source,
142                                                   int                start,
143                                                   int                len,
144                                                   DBusString        *dest,
145                                                   int                insert_at);
146 dbus_bool_t   _dbus_string_replace_len           (const DBusString  *source,
147                                                   int                start,
148                                                   int                len,
149                                                   DBusString        *dest,
150                                                   int                replace_at,
151                                                   int                replace_len);
152 void          _dbus_string_get_unichar           (const DBusString  *str,
153                                                   int                start,
154                                                   dbus_unichar_t    *ch_return,
155                                                   int               *end_return);
156 dbus_bool_t   _dbus_string_parse_int             (const DBusString  *str,
157                                                   int                start,
158                                                   long              *value_return,
159                                                   int               *end_return);
160 dbus_bool_t   _dbus_string_parse_uint            (const DBusString  *str,
161                                                   int                start,
162                                                   unsigned long     *value_return,
163                                                   int               *end_return);
164 dbus_bool_t   _dbus_string_parse_double          (const DBusString  *str,
165                                                   int                start,
166                                                   double            *value,
167                                                   int               *end_return);
168 dbus_bool_t   _dbus_string_find                  (const DBusString  *str,
169                                                   int                start,
170                                                   const char        *substr,
171                                                   int               *found);
172 dbus_bool_t   _dbus_string_find_to               (const DBusString  *str,
173                                                   int                start,
174                                                   int                end,
175                                                   const char        *substr,
176                                                   int               *found);
177 dbus_bool_t   _dbus_string_find_byte_backward    (const DBusString  *str,
178                                                   int                start,
179                                                   unsigned char      byte,
180                                                   int               *found);
181 dbus_bool_t   _dbus_string_find_blank            (const DBusString  *str,
182                                                   int                start,
183                                                   int               *found);
184 void          _dbus_string_skip_blank            (const DBusString  *str,
185                                                   int                start,
186                                                   int               *end);
187 void          _dbus_string_skip_white            (const DBusString  *str,
188                                                   int                start,
189                                                   int               *end);
190 dbus_bool_t   _dbus_string_equal                 (const DBusString  *a,
191                                                   const DBusString  *b);
192 dbus_bool_t   _dbus_string_equal_c_str           (const DBusString  *a,
193                                                   const char        *c_str);
194 dbus_bool_t   _dbus_string_equal_len             (const DBusString  *a,
195                                                   const DBusString  *b,
196                                                   int                len);
197 dbus_bool_t   _dbus_string_starts_with_c_str     (const DBusString  *a,
198                                                   const char        *c_str);
199 dbus_bool_t   _dbus_string_ends_with_c_str       (const DBusString  *a,
200                                                   const char        *c_str);
201 dbus_bool_t   _dbus_string_pop_line              (DBusString        *source,
202                                                   DBusString        *dest);
203 void          _dbus_string_delete_first_word     (DBusString        *str);
204 void          _dbus_string_delete_leading_blanks (DBusString        *str);
205 dbus_bool_t   _dbus_string_base64_encode         (const DBusString  *source,
206                                                   int                start,
207                                                   DBusString        *dest,
208                                                   int                insert_at);
209 dbus_bool_t   _dbus_string_base64_decode         (const DBusString  *source,
210                                                   int                start,
211                                                   DBusString        *dest,
212                                                   int                insert_at);
213 dbus_bool_t   _dbus_string_hex_encode            (const DBusString  *source,
214                                                   int                start,
215                                                   DBusString        *dest,
216                                                   int                insert_at);
217 dbus_bool_t   _dbus_string_hex_decode            (const DBusString  *source,
218                                                   int                start,
219                                                   DBusString        *dest,
220                                                   int                insert_at);
221 dbus_bool_t   _dbus_string_validate_ascii        (const DBusString  *str,
222                                                   int                start,
223                                                   int                len);
224 dbus_bool_t   _dbus_string_validate_utf8         (const DBusString  *str,
225                                                   int                start,
226                                                   int                len);
227 dbus_bool_t   _dbus_string_validate_nul          (const DBusString  *str,
228                                                   int                start,
229                                                   int                len);
230 dbus_bool_t   _dbus_string_validate_path         (const DBusString  *str,
231                                                   int                start,
232                                                   int                len);
233 dbus_bool_t   _dbus_string_validate_interface    (const DBusString  *str,
234                                                   int                start,
235                                                   int                len);
236 dbus_bool_t   _dbus_string_validate_member       (const DBusString  *str,
237                                                   int                start,
238                                                   int                len);
239 dbus_bool_t   _dbus_string_validate_error_name   (const DBusString  *str,
240                                                   int                start,
241                                                   int                len);
242 dbus_bool_t   _dbus_string_validate_service      (const DBusString  *str,
243                                                   int                start,
244                                                   int                len);
245 void          _dbus_string_zero                  (DBusString        *str);
246
247
248 DBUS_END_DECLS;
249
250 #endif /* DBUS_STRING_H */