add 2.36 index to gobject docs
[glib.git] / glib / gstrfuncs.h
blob510623a941db4e691b482c783492f51a65c0e546
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 #ifndef __G_STRFUNCS_H__
28 #define __G_STRFUNCS_H__
30 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31 #error "Only <glib.h> can be included directly."
32 #endif
34 #include <stdarg.h>
35 #include <glib/gmacros.h>
36 #include <glib/gtypes.h>
38 G_BEGIN_DECLS
40 /* Functions like the ones in <ctype.h> that are not affected by locale. */
41 typedef enum {
42 G_ASCII_ALNUM = 1 << 0,
43 G_ASCII_ALPHA = 1 << 1,
44 G_ASCII_CNTRL = 1 << 2,
45 G_ASCII_DIGIT = 1 << 3,
46 G_ASCII_GRAPH = 1 << 4,
47 G_ASCII_LOWER = 1 << 5,
48 G_ASCII_PRINT = 1 << 6,
49 G_ASCII_PUNCT = 1 << 7,
50 G_ASCII_SPACE = 1 << 8,
51 G_ASCII_UPPER = 1 << 9,
52 G_ASCII_XDIGIT = 1 << 10
53 } GAsciiType;
55 GLIB_VAR const guint16 * const g_ascii_table;
57 #define g_ascii_isalnum(c) \
58 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
60 #define g_ascii_isalpha(c) \
61 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
63 #define g_ascii_iscntrl(c) \
64 ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
66 #define g_ascii_isdigit(c) \
67 ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
69 #define g_ascii_isgraph(c) \
70 ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
72 #define g_ascii_islower(c) \
73 ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
75 #define g_ascii_isprint(c) \
76 ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
78 #define g_ascii_ispunct(c) \
79 ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
81 #define g_ascii_isspace(c) \
82 ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
84 #define g_ascii_isupper(c) \
85 ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
87 #define g_ascii_isxdigit(c) \
88 ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
90 GLIB_AVAILABLE_IN_ALL
91 gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
92 GLIB_AVAILABLE_IN_ALL
93 gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
95 GLIB_AVAILABLE_IN_ALL
96 gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
97 GLIB_AVAILABLE_IN_ALL
98 gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
100 /* String utility functions that modify a string argument or
101 * return a constant string that must not be freed.
103 #define G_STR_DELIMITERS "_-|> <."
104 GLIB_AVAILABLE_IN_ALL
105 gchar* g_strdelimit (gchar *string,
106 const gchar *delimiters,
107 gchar new_delimiter);
108 GLIB_AVAILABLE_IN_ALL
109 gchar* g_strcanon (gchar *string,
110 const gchar *valid_chars,
111 gchar substitutor);
112 GLIB_AVAILABLE_IN_ALL
113 const gchar * g_strerror (gint errnum) G_GNUC_CONST;
114 GLIB_AVAILABLE_IN_ALL
115 const gchar * g_strsignal (gint signum) G_GNUC_CONST;
116 GLIB_AVAILABLE_IN_ALL
117 gchar * g_strreverse (gchar *string);
118 GLIB_AVAILABLE_IN_ALL
119 gsize g_strlcpy (gchar *dest,
120 const gchar *src,
121 gsize dest_size);
122 GLIB_AVAILABLE_IN_ALL
123 gsize g_strlcat (gchar *dest,
124 const gchar *src,
125 gsize dest_size);
126 GLIB_AVAILABLE_IN_ALL
127 gchar * g_strstr_len (const gchar *haystack,
128 gssize haystack_len,
129 const gchar *needle);
130 GLIB_AVAILABLE_IN_ALL
131 gchar * g_strrstr (const gchar *haystack,
132 const gchar *needle);
133 GLIB_AVAILABLE_IN_ALL
134 gchar * g_strrstr_len (const gchar *haystack,
135 gssize haystack_len,
136 const gchar *needle);
138 GLIB_AVAILABLE_IN_ALL
139 gboolean g_str_has_suffix (const gchar *str,
140 const gchar *suffix);
141 GLIB_AVAILABLE_IN_ALL
142 gboolean g_str_has_prefix (const gchar *str,
143 const gchar *prefix);
145 /* String to/from double conversion functions */
147 GLIB_AVAILABLE_IN_ALL
148 gdouble g_strtod (const gchar *nptr,
149 gchar **endptr);
150 GLIB_AVAILABLE_IN_ALL
151 gdouble g_ascii_strtod (const gchar *nptr,
152 gchar **endptr);
153 GLIB_AVAILABLE_IN_ALL
154 guint64 g_ascii_strtoull (const gchar *nptr,
155 gchar **endptr,
156 guint base);
157 GLIB_AVAILABLE_IN_ALL
158 gint64 g_ascii_strtoll (const gchar *nptr,
159 gchar **endptr,
160 guint base);
161 /* 29 bytes should enough for all possible values that
162 * g_ascii_dtostr can produce.
163 * Then add 10 for good measure */
164 #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
165 GLIB_AVAILABLE_IN_ALL
166 gchar * g_ascii_dtostr (gchar *buffer,
167 gint buf_len,
168 gdouble d);
169 GLIB_AVAILABLE_IN_ALL
170 gchar * g_ascii_formatd (gchar *buffer,
171 gint buf_len,
172 const gchar *format,
173 gdouble d);
175 /* removes leading spaces */
176 GLIB_AVAILABLE_IN_ALL
177 gchar* g_strchug (gchar *string);
178 /* removes trailing spaces */
179 GLIB_AVAILABLE_IN_ALL
180 gchar* g_strchomp (gchar *string);
181 /* removes leading & trailing spaces */
182 #define g_strstrip( string ) g_strchomp (g_strchug (string))
184 GLIB_AVAILABLE_IN_ALL
185 gint g_ascii_strcasecmp (const gchar *s1,
186 const gchar *s2);
187 GLIB_AVAILABLE_IN_ALL
188 gint g_ascii_strncasecmp (const gchar *s1,
189 const gchar *s2,
190 gsize n);
191 GLIB_AVAILABLE_IN_ALL
192 gchar* g_ascii_strdown (const gchar *str,
193 gssize len) G_GNUC_MALLOC;
194 GLIB_AVAILABLE_IN_ALL
195 gchar* g_ascii_strup (const gchar *str,
196 gssize len) G_GNUC_MALLOC;
199 GLIB_DEPRECATED
200 gint g_strcasecmp (const gchar *s1,
201 const gchar *s2);
202 GLIB_DEPRECATED
203 gint g_strncasecmp (const gchar *s1,
204 const gchar *s2,
205 guint n);
206 GLIB_DEPRECATED
207 gchar* g_strdown (gchar *string);
208 GLIB_DEPRECATED
209 gchar* g_strup (gchar *string);
212 /* String utility functions that return a newly allocated string which
213 * ought to be freed with g_free from the caller at some point.
215 GLIB_AVAILABLE_IN_ALL
216 gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
217 GLIB_AVAILABLE_IN_ALL
218 gchar* g_strdup_printf (const gchar *format,
219 ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
220 GLIB_AVAILABLE_IN_ALL
221 gchar* g_strdup_vprintf (const gchar *format,
222 va_list args) G_GNUC_PRINTF(1, 0)
223 G_GNUC_MALLOC;
224 GLIB_AVAILABLE_IN_ALL
225 gchar* g_strndup (const gchar *str,
226 gsize n) G_GNUC_MALLOC;
227 GLIB_AVAILABLE_IN_ALL
228 gchar* g_strnfill (gsize length,
229 gchar fill_char) G_GNUC_MALLOC;
230 GLIB_AVAILABLE_IN_ALL
231 gchar* g_strconcat (const gchar *string1,
232 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
233 GLIB_AVAILABLE_IN_ALL
234 gchar* g_strjoin (const gchar *separator,
235 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
237 /* Make a copy of a string interpreting C string -style escape
238 * sequences. Inverse of g_strescape. The recognized sequences are \b
239 * \f \n \r \t \\ \" and the octal format.
241 GLIB_AVAILABLE_IN_ALL
242 gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
244 /* Copy a string escaping nonprintable characters like in C strings.
245 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
246 * to a string containing characters that are not to be escaped.
248 * Deprecated API: gchar* g_strescape (const gchar *source);
249 * Luckily this function wasn't used much, using NULL as second parameter
250 * provides mostly identical semantics.
252 GLIB_AVAILABLE_IN_ALL
253 gchar* g_strescape (const gchar *source,
254 const gchar *exceptions) G_GNUC_MALLOC;
256 GLIB_AVAILABLE_IN_ALL
257 gpointer g_memdup (gconstpointer mem,
258 guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
260 /* NULL terminated string arrays.
261 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
262 * at delim and return a newly allocated string array.
263 * g_strjoinv() concatenates all of str_array's strings, sliding in an
264 * optional separator, the returned string is newly allocated.
265 * g_strfreev() frees the array itself and all of its strings.
266 * g_strdupv() copies a NULL-terminated array of strings
267 * g_strv_length() returns the length of a NULL-terminated array of strings
269 GLIB_AVAILABLE_IN_ALL
270 gchar** g_strsplit (const gchar *string,
271 const gchar *delimiter,
272 gint max_tokens) G_GNUC_MALLOC;
273 GLIB_AVAILABLE_IN_ALL
274 gchar ** g_strsplit_set (const gchar *string,
275 const gchar *delimiters,
276 gint max_tokens) G_GNUC_MALLOC;
277 GLIB_AVAILABLE_IN_ALL
278 gchar* g_strjoinv (const gchar *separator,
279 gchar **str_array) G_GNUC_MALLOC;
280 GLIB_AVAILABLE_IN_ALL
281 void g_strfreev (gchar **str_array);
282 GLIB_AVAILABLE_IN_ALL
283 gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC;
284 GLIB_AVAILABLE_IN_ALL
285 guint g_strv_length (gchar **str_array);
287 GLIB_AVAILABLE_IN_ALL
288 gchar* g_stpcpy (gchar *dest,
289 const char *src);
291 G_END_DECLS
293 #endif /* __G_STRFUNCS_H__ */