|
1 /* GLIB - Library of useful routines for C programming |
|
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
|
3 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Lesser General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Lesser General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Lesser General Public |
|
16 * License along with this library; if not, write to the |
|
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 * Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 /* |
|
22 * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
|
23 * file for a list of people on the GLib Team. See the ChangeLog |
|
24 * files for a list of changes. These files are distributed with |
|
25 * GLib at ftp://ftp.gtk.org/pub/gtk/. |
|
26 */ |
|
27 |
|
28 #ifndef __G_STRFUNCS_H__ |
|
29 #define __G_STRFUNCS_H__ |
|
30 |
|
31 #include <_ansi.h> |
|
32 #include <stdarg.h> |
|
33 #include <glib/gtypes.h> |
|
34 |
|
35 G_BEGIN_DECLS |
|
36 |
|
37 /* Functions like the ones in <ctype.h> that are not affected by locale. */ |
|
38 typedef enum { |
|
39 G_ASCII_ALNUM = 1 << 0, |
|
40 G_ASCII_ALPHA = 1 << 1, |
|
41 G_ASCII_CNTRL = 1 << 2, |
|
42 G_ASCII_DIGIT = 1 << 3, |
|
43 G_ASCII_GRAPH = 1 << 4, |
|
44 G_ASCII_LOWER = 1 << 5, |
|
45 G_ASCII_PRINT = 1 << 6, |
|
46 G_ASCII_PUNCT = 1 << 7, |
|
47 G_ASCII_SPACE = 1 << 8, |
|
48 G_ASCII_UPPER = 1 << 9, |
|
49 G_ASCII_XDIGIT = 1 << 10 |
|
50 } GAsciiType; |
|
51 |
|
52 #ifdef __SYMBIAN32__ |
|
53 IMPORT_C const guint16 * const * _g_ascii_table(); |
|
54 #endif /* __SYMBIAN32__ */ |
|
55 GLIB_VAR const guint16 * const g_ascii_table; |
|
56 |
|
57 #define g_ascii_isalnum(c) \ |
|
58 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0) |
|
59 |
|
60 #define g_ascii_isalpha(c) \ |
|
61 ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0) |
|
62 |
|
63 #define g_ascii_iscntrl(c) \ |
|
64 ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0) |
|
65 |
|
66 #define g_ascii_isdigit(c) \ |
|
67 ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0) |
|
68 |
|
69 #define g_ascii_isgraph(c) \ |
|
70 ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0) |
|
71 |
|
72 #define g_ascii_islower(c) \ |
|
73 ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0) |
|
74 |
|
75 #define g_ascii_isprint(c) \ |
|
76 ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0) |
|
77 |
|
78 #define g_ascii_ispunct(c) \ |
|
79 ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0) |
|
80 |
|
81 #define g_ascii_isspace(c) \ |
|
82 ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0) |
|
83 |
|
84 #define g_ascii_isupper(c) \ |
|
85 ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0) |
|
86 |
|
87 #define g_ascii_isxdigit(c) \ |
|
88 ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0) |
|
89 |
|
90 IMPORT_C gchar g_ascii_tolower (gchar c) G_GNUC_CONST; |
|
91 IMPORT_C gchar g_ascii_toupper (gchar c) G_GNUC_CONST; |
|
92 |
|
93 IMPORT_C gint g_ascii_digit_value (gchar c) G_GNUC_CONST; |
|
94 IMPORT_C gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST; |
|
95 |
|
96 /* String utility functions that modify a string argument or |
|
97 * return a constant string that must not be freed. |
|
98 */ |
|
99 #define G_STR_DELIMITERS "_-|> <." |
|
100 IMPORT_C gchar* g_strdelimit (gchar *string, |
|
101 const gchar *delimiters, |
|
102 gchar new_delimiter); |
|
103 IMPORT_C gchar* g_strcanon (gchar *string, |
|
104 const gchar *valid_chars, |
|
105 gchar substitutor); |
|
106 IMPORT_C G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST; |
|
107 IMPORT_C G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST; |
|
108 IMPORT_C gchar* g_strreverse (gchar *string); |
|
109 IMPORT_C gsize g_strlcpy (gchar *dest, |
|
110 const gchar *src, |
|
111 gsize dest_size); |
|
112 IMPORT_C gsize g_strlcat (gchar *dest, |
|
113 const gchar *src, |
|
114 gsize dest_size); |
|
115 IMPORT_C gchar * g_strstr_len (const gchar *haystack, |
|
116 gssize haystack_len, |
|
117 const gchar *needle); |
|
118 IMPORT_C gchar * g_strrstr (const gchar *haystack, |
|
119 const gchar *needle); |
|
120 IMPORT_C gchar * g_strrstr_len (const gchar *haystack, |
|
121 gssize haystack_len, |
|
122 const gchar *needle); |
|
123 |
|
124 IMPORT_C gboolean g_str_has_suffix (const gchar *str, |
|
125 const gchar *suffix); |
|
126 IMPORT_C gboolean g_str_has_prefix (const gchar *str, |
|
127 const gchar *prefix); |
|
128 |
|
129 /* String to/from double conversion functions */ |
|
130 |
|
131 IMPORT_C gdouble g_strtod (const gchar *nptr, |
|
132 gchar **endptr); |
|
133 IMPORT_C gdouble g_ascii_strtod (const gchar *nptr, |
|
134 gchar **endptr); |
|
135 IMPORT_C guint64 g_ascii_strtoull (const gchar *nptr, |
|
136 gchar **endptr, |
|
137 guint base); |
|
138 /* 29 bytes should enough for all possible values that |
|
139 * g_ascii_dtostr can produce. |
|
140 * Then add 10 for good measure */ |
|
141 #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10) |
|
142 IMPORT_C gchar * g_ascii_dtostr (gchar *buffer, |
|
143 gint buf_len, |
|
144 gdouble d); |
|
145 IMPORT_C gchar * g_ascii_formatd (gchar *buffer, |
|
146 gint buf_len, |
|
147 const gchar *format, |
|
148 gdouble d); |
|
149 |
|
150 /* removes leading spaces */ |
|
151 IMPORT_C gchar* g_strchug (gchar *string); |
|
152 /* removes trailing spaces */ |
|
153 IMPORT_C gchar* g_strchomp (gchar *string); |
|
154 /* removes leading & trailing spaces */ |
|
155 #define g_strstrip( string ) g_strchomp (g_strchug (string)) |
|
156 |
|
157 IMPORT_C gint g_ascii_strcasecmp (const gchar *s1, |
|
158 const gchar *s2); |
|
159 IMPORT_C gint g_ascii_strncasecmp (const gchar *s1, |
|
160 const gchar *s2, |
|
161 gsize n); |
|
162 IMPORT_C gchar* g_ascii_strdown (const gchar *str, |
|
163 gssize len) G_GNUC_MALLOC; |
|
164 IMPORT_C gchar* g_ascii_strup (const gchar *str, |
|
165 gssize len) G_GNUC_MALLOC; |
|
166 |
|
167 #ifndef G_DISABLE_DEPRECATED |
|
168 |
|
169 /* The following four functions are deprecated and will be removed in |
|
170 * the next major release. They use the locale-specific tolower and |
|
171 * toupper, which is almost never the right thing. |
|
172 */ |
|
173 |
|
174 IMPORT_C gint g_strcasecmp (const gchar *s1, |
|
175 const gchar *s2); |
|
176 IMPORT_C gint g_strncasecmp (const gchar *s1, |
|
177 const gchar *s2, |
|
178 guint n); |
|
179 IMPORT_C gchar* g_strdown (gchar *string); |
|
180 IMPORT_C gchar* g_strup (gchar *string); |
|
181 |
|
182 #endif /* G_DISABLE_DEPRECATED */ |
|
183 |
|
184 /* String utility functions that return a newly allocated string which |
|
185 * ought to be freed with g_free from the caller at some point. |
|
186 */ |
|
187 IMPORT_C gchar* g_strdup (const gchar *str) G_GNUC_MALLOC; |
|
188 IMPORT_C gchar* g_strdup_printf (const gchar *format, |
|
189 ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC; |
|
190 IMPORT_C gchar* g_strdup_vprintf (const gchar *format, |
|
191 va_list args) G_GNUC_MALLOC; |
|
192 IMPORT_C gchar* g_strndup (const gchar *str, |
|
193 gsize n) G_GNUC_MALLOC; |
|
194 IMPORT_C gchar* g_strnfill (gsize length, |
|
195 gchar fill_char) G_GNUC_MALLOC; |
|
196 IMPORT_C gchar* g_strconcat (const gchar *string1, |
|
197 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; |
|
198 IMPORT_C gchar* g_strjoin (const gchar *separator, |
|
199 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; |
|
200 |
|
201 /* Make a copy of a string interpreting C string -style escape |
|
202 * sequences. Inverse of g_strescape. The recognized sequences are \b |
|
203 * \f \n \r \t \\ \" and the octal format. |
|
204 */ |
|
205 IMPORT_C gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC; |
|
206 |
|
207 /* Copy a string escaping nonprintable characters like in C strings. |
|
208 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points |
|
209 * to a string containing characters that are not to be escaped. |
|
210 * |
|
211 * Deprecated API: gchar* g_strescape (const gchar *source); |
|
212 * Luckily this function wasn't used much, using NULL as second parameter |
|
213 * provides mostly identical semantics. |
|
214 */ |
|
215 IMPORT_C gchar* g_strescape (const gchar *source, |
|
216 const gchar *exceptions) G_GNUC_MALLOC; |
|
217 |
|
218 IMPORT_C gpointer g_memdup (gconstpointer mem, |
|
219 guint byte_size) G_GNUC_MALLOC; |
|
220 |
|
221 /* NULL terminated string arrays. |
|
222 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens |
|
223 * at delim and return a newly allocated string array. |
|
224 * g_strjoinv() concatenates all of str_array's strings, sliding in an |
|
225 * optional separator, the returned string is newly allocated. |
|
226 * g_strfreev() frees the array itself and all of its strings. |
|
227 * g_strdupv() copies a NULL-terminated array of strings |
|
228 * g_strv_length() returns the length of a NULL-terminated array of strings |
|
229 */ |
|
230 IMPORT_C gchar** g_strsplit (const gchar *string, |
|
231 const gchar *delimiter, |
|
232 gint max_tokens) G_GNUC_MALLOC; |
|
233 IMPORT_C gchar ** g_strsplit_set (const gchar *string, |
|
234 const gchar *delimiters, |
|
235 gint max_tokens) G_GNUC_MALLOC; |
|
236 IMPORT_C gchar* g_strjoinv (const gchar *separator, |
|
237 gchar **str_array) G_GNUC_MALLOC; |
|
238 IMPORT_C void g_strfreev (gchar **str_array); |
|
239 IMPORT_C gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC; |
|
240 IMPORT_C guint g_strv_length (gchar **str_array); |
|
241 |
|
242 IMPORT_C gchar* g_stpcpy (gchar *dest, |
|
243 const char *src); |
|
244 |
|
245 IMPORT_C G_CONST_RETURN gchar *g_strip_context (const gchar *msgid, |
|
246 const gchar *msgval); |
|
247 |
|
248 G_END_DECLS |
|
249 |
|
250 #endif /* __G_STRFUNCS_H__ */ |