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