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."
35 #include <glib/gmacros.h>
36 #include <glib/gtypes.h>
40 /* Functions like the ones in <ctype.h> that are not affected by locale. */
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
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)
91 gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
93 gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
96 gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
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,
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,
122 GLIB_AVAILABLE_IN_ALL
123 gsize g_strlcat (gchar *dest,
126 GLIB_AVAILABLE_IN_ALL
127 gchar * g_strstr_len (const gchar *haystack,
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,
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,
150 GLIB_AVAILABLE_IN_ALL
151 gdouble g_ascii_strtod (const gchar *nptr,
153 GLIB_AVAILABLE_IN_ALL
154 guint64 g_ascii_strtoull (const gchar *nptr,
157 GLIB_AVAILABLE_IN_ALL
158 gint64 g_ascii_strtoll (const gchar *nptr,
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,
169 GLIB_AVAILABLE_IN_ALL
170 gchar * g_ascii_formatd (gchar *buffer,
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,
187 GLIB_AVAILABLE_IN_ALL
188 gint g_ascii_strncasecmp (const gchar *s1,
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;
198 GLIB_AVAILABLE_IN_2_40
199 gboolean g_str_is_ascii (const gchar *str);
202 gint g_strcasecmp (const gchar *s1,
205 gint g_strncasecmp (const gchar *s1,
209 gchar* g_strdown (gchar *string);
211 gchar* g_strup (gchar *string);
214 /* String utility functions that return a newly allocated string which
215 * ought to be freed with g_free from the caller at some point.
217 GLIB_AVAILABLE_IN_ALL
218 gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
219 GLIB_AVAILABLE_IN_ALL
220 gchar* g_strdup_printf (const gchar *format,
221 ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
222 GLIB_AVAILABLE_IN_ALL
223 gchar* g_strdup_vprintf (const gchar *format,
224 va_list args) G_GNUC_PRINTF(1, 0)
226 GLIB_AVAILABLE_IN_ALL
227 gchar* g_strndup (const gchar *str,
228 gsize n) G_GNUC_MALLOC;
229 GLIB_AVAILABLE_IN_ALL
230 gchar* g_strnfill (gsize length,
231 gchar fill_char) G_GNUC_MALLOC;
232 GLIB_AVAILABLE_IN_ALL
233 gchar* g_strconcat (const gchar *string1,
234 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
235 GLIB_AVAILABLE_IN_ALL
236 gchar* g_strjoin (const gchar *separator,
237 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
239 /* Make a copy of a string interpreting C string -style escape
240 * sequences. Inverse of g_strescape. The recognized sequences are \b
241 * \f \n \r \t \\ \" and the octal format.
243 GLIB_AVAILABLE_IN_ALL
244 gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
246 /* Copy a string escaping nonprintable characters like in C strings.
247 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
248 * to a string containing characters that are not to be escaped.
250 * Deprecated API: gchar* g_strescape (const gchar *source);
251 * Luckily this function wasn't used much, using NULL as second parameter
252 * provides mostly identical semantics.
254 GLIB_AVAILABLE_IN_ALL
255 gchar* g_strescape (const gchar *source,
256 const gchar *exceptions) G_GNUC_MALLOC;
258 GLIB_AVAILABLE_IN_ALL
259 gpointer g_memdup (gconstpointer mem,
260 guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
262 /* NULL terminated string arrays.
263 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
264 * at delim and return a newly allocated string array.
265 * g_strjoinv() concatenates all of str_array's strings, sliding in an
266 * optional separator, the returned string is newly allocated.
267 * g_strfreev() frees the array itself and all of its strings.
268 * g_strdupv() copies a NULL-terminated array of strings
269 * g_strv_length() returns the length of a NULL-terminated array of strings
271 GLIB_AVAILABLE_IN_ALL
272 gchar** g_strsplit (const gchar *string,
273 const gchar *delimiter,
274 gint max_tokens) G_GNUC_MALLOC;
275 GLIB_AVAILABLE_IN_ALL
276 gchar ** g_strsplit_set (const gchar *string,
277 const gchar *delimiters,
278 gint max_tokens) G_GNUC_MALLOC;
279 GLIB_AVAILABLE_IN_ALL
280 gchar* g_strjoinv (const gchar *separator,
281 gchar **str_array) G_GNUC_MALLOC;
282 GLIB_AVAILABLE_IN_ALL
283 void g_strfreev (gchar **str_array);
284 GLIB_AVAILABLE_IN_ALL
285 gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC;
286 GLIB_AVAILABLE_IN_ALL
287 guint g_strv_length (gchar **str_array);
289 GLIB_AVAILABLE_IN_ALL
290 gchar* g_stpcpy (gchar *dest,
293 GLIB_AVAILABLE_IN_2_40
294 gchar ** g_str_tokenize_and_fold (const gchar *string,
295 const gchar *translit_locale,
296 gchar ***ascii_alternates);
298 GLIB_AVAILABLE_IN_2_40
299 gboolean g_str_match_string (const gchar *search_term,
300 const gchar *potential_hit,
301 gboolean accept_alternates);
305 #endif /* __G_STRFUNCS_H__ */