Add some more cases to the app-id unit tests
[glib.git] / glib / gstrfuncs.h
blobbc0c48e315aac728e4b96d28ad82adfd48390ce5
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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 #ifndef __G_STRFUNCS_H__
26 #define __G_STRFUNCS_H__
28 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29 #error "Only <glib.h> can be included directly."
30 #endif
32 #include <stdarg.h>
33 #include <glib/gmacros.h>
34 #include <glib/gtypes.h>
36 G_BEGIN_DECLS
38 /* Functions like the ones in <ctype.h> that are not affected by locale. */
39 typedef enum {
40 G_ASCII_ALNUM = 1 << 0,
41 G_ASCII_ALPHA = 1 << 1,
42 G_ASCII_CNTRL = 1 << 2,
43 G_ASCII_DIGIT = 1 << 3,
44 G_ASCII_GRAPH = 1 << 4,
45 G_ASCII_LOWER = 1 << 5,
46 G_ASCII_PRINT = 1 << 6,
47 G_ASCII_PUNCT = 1 << 7,
48 G_ASCII_SPACE = 1 << 8,
49 G_ASCII_UPPER = 1 << 9,
50 G_ASCII_XDIGIT = 1 << 10
51 } GAsciiType;
53 GLIB_VAR const guint16 * const g_ascii_table;
55 #define g_ascii_isalnum(c) \
56 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
58 #define g_ascii_isalpha(c) \
59 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
61 #define g_ascii_iscntrl(c) \
62 ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
64 #define g_ascii_isdigit(c) \
65 ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
67 #define g_ascii_isgraph(c) \
68 ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
70 #define g_ascii_islower(c) \
71 ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
73 #define g_ascii_isprint(c) \
74 ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
76 #define g_ascii_ispunct(c) \
77 ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
79 #define g_ascii_isspace(c) \
80 ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
82 #define g_ascii_isupper(c) \
83 ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
85 #define g_ascii_isxdigit(c) \
86 ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
88 GLIB_AVAILABLE_IN_ALL
89 gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
90 GLIB_AVAILABLE_IN_ALL
91 gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
93 GLIB_AVAILABLE_IN_ALL
94 gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
95 GLIB_AVAILABLE_IN_ALL
96 gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
98 /* String utility functions that modify a string argument or
99 * return a constant string that must not be freed.
101 #define G_STR_DELIMITERS "_-|> <."
102 GLIB_AVAILABLE_IN_ALL
103 gchar* g_strdelimit (gchar *string,
104 const gchar *delimiters,
105 gchar new_delimiter);
106 GLIB_AVAILABLE_IN_ALL
107 gchar* g_strcanon (gchar *string,
108 const gchar *valid_chars,
109 gchar substitutor);
110 GLIB_AVAILABLE_IN_ALL
111 const gchar * g_strerror (gint errnum) G_GNUC_CONST;
112 GLIB_AVAILABLE_IN_ALL
113 const gchar * g_strsignal (gint signum) G_GNUC_CONST;
114 GLIB_AVAILABLE_IN_ALL
115 gchar * g_strreverse (gchar *string);
116 GLIB_AVAILABLE_IN_ALL
117 gsize g_strlcpy (gchar *dest,
118 const gchar *src,
119 gsize dest_size);
120 GLIB_AVAILABLE_IN_ALL
121 gsize g_strlcat (gchar *dest,
122 const gchar *src,
123 gsize dest_size);
124 GLIB_AVAILABLE_IN_ALL
125 gchar * g_strstr_len (const gchar *haystack,
126 gssize haystack_len,
127 const gchar *needle);
128 GLIB_AVAILABLE_IN_ALL
129 gchar * g_strrstr (const gchar *haystack,
130 const gchar *needle);
131 GLIB_AVAILABLE_IN_ALL
132 gchar * g_strrstr_len (const gchar *haystack,
133 gssize haystack_len,
134 const gchar *needle);
136 GLIB_AVAILABLE_IN_ALL
137 gboolean g_str_has_suffix (const gchar *str,
138 const gchar *suffix);
139 GLIB_AVAILABLE_IN_ALL
140 gboolean g_str_has_prefix (const gchar *str,
141 const gchar *prefix);
143 /* String to/from double conversion functions */
145 GLIB_AVAILABLE_IN_ALL
146 gdouble g_strtod (const gchar *nptr,
147 gchar **endptr);
148 GLIB_AVAILABLE_IN_ALL
149 gdouble g_ascii_strtod (const gchar *nptr,
150 gchar **endptr);
151 GLIB_AVAILABLE_IN_ALL
152 guint64 g_ascii_strtoull (const gchar *nptr,
153 gchar **endptr,
154 guint base);
155 GLIB_AVAILABLE_IN_ALL
156 gint64 g_ascii_strtoll (const gchar *nptr,
157 gchar **endptr,
158 guint base);
159 /* 29 bytes should enough for all possible values that
160 * g_ascii_dtostr can produce.
161 * Then add 10 for good measure */
162 #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
163 GLIB_AVAILABLE_IN_ALL
164 gchar * g_ascii_dtostr (gchar *buffer,
165 gint buf_len,
166 gdouble d);
167 GLIB_AVAILABLE_IN_ALL
168 gchar * g_ascii_formatd (gchar *buffer,
169 gint buf_len,
170 const gchar *format,
171 gdouble d);
173 /* removes leading spaces */
174 GLIB_AVAILABLE_IN_ALL
175 gchar* g_strchug (gchar *string);
176 /* removes trailing spaces */
177 GLIB_AVAILABLE_IN_ALL
178 gchar* g_strchomp (gchar *string);
179 /* removes leading & trailing spaces */
180 #define g_strstrip( string ) g_strchomp (g_strchug (string))
182 GLIB_AVAILABLE_IN_ALL
183 gint g_ascii_strcasecmp (const gchar *s1,
184 const gchar *s2);
185 GLIB_AVAILABLE_IN_ALL
186 gint g_ascii_strncasecmp (const gchar *s1,
187 const gchar *s2,
188 gsize n);
189 GLIB_AVAILABLE_IN_ALL
190 gchar* g_ascii_strdown (const gchar *str,
191 gssize len) G_GNUC_MALLOC;
192 GLIB_AVAILABLE_IN_ALL
193 gchar* g_ascii_strup (const gchar *str,
194 gssize len) G_GNUC_MALLOC;
196 GLIB_AVAILABLE_IN_2_40
197 gboolean g_str_is_ascii (const gchar *str);
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) G_GNUC_MALLOC;
223 GLIB_AVAILABLE_IN_ALL
224 gchar* g_strndup (const gchar *str,
225 gsize n) G_GNUC_MALLOC;
226 GLIB_AVAILABLE_IN_ALL
227 gchar* g_strnfill (gsize length,
228 gchar fill_char) G_GNUC_MALLOC;
229 GLIB_AVAILABLE_IN_ALL
230 gchar* g_strconcat (const gchar *string1,
231 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
232 GLIB_AVAILABLE_IN_ALL
233 gchar* g_strjoin (const gchar *separator,
234 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
236 /* Make a copy of a string interpreting C string -style escape
237 * sequences. Inverse of g_strescape. The recognized sequences are \b
238 * \f \n \r \t \\ \" and the octal format.
240 GLIB_AVAILABLE_IN_ALL
241 gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
243 /* Copy a string escaping nonprintable characters like in C strings.
244 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
245 * to a string containing characters that are not to be escaped.
247 * Deprecated API: gchar* g_strescape (const gchar *source);
248 * Luckily this function wasn't used much, using NULL as second parameter
249 * provides mostly identical semantics.
251 GLIB_AVAILABLE_IN_ALL
252 gchar* g_strescape (const gchar *source,
253 const gchar *exceptions) G_GNUC_MALLOC;
255 GLIB_AVAILABLE_IN_ALL
256 gpointer g_memdup (gconstpointer mem,
257 guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
259 /* NULL terminated string arrays.
260 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
261 * at delim and return a newly allocated string array.
262 * g_strjoinv() concatenates all of str_array's strings, sliding in an
263 * optional separator, the returned string is newly allocated.
264 * g_strfreev() frees the array itself and all of its strings.
265 * g_strdupv() copies a NULL-terminated array of strings
266 * g_strv_length() returns the length of a NULL-terminated array of strings
268 typedef gchar** GStrv;
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 GLIB_AVAILABLE_IN_2_40
292 gchar * g_str_to_ascii (const gchar *str,
293 const gchar *from_locale);
295 GLIB_AVAILABLE_IN_2_40
296 gchar ** g_str_tokenize_and_fold (const gchar *string,
297 const gchar *translit_locale,
298 gchar ***ascii_alternates);
300 GLIB_AVAILABLE_IN_2_40
301 gboolean g_str_match_string (const gchar *search_term,
302 const gchar *potential_hit,
303 gboolean accept_alternates);
305 GLIB_AVAILABLE_IN_2_44
306 gboolean g_strv_contains (const gchar * const *strv,
307 const gchar *str);
309 G_END_DECLS
311 #endif /* __G_STRFUNCS_H__ */