Call setlocale initially
[glib.git] / glib / gstrfuncs.h
blob534f26e3729877998c3e2f7aca856d4d41ce2951
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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
31 #ifndef __G_STRFUNCS_H__
32 #define __G_STRFUNCS_H__
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 gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
91 gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
93 gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
94 gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
96 /* String utility functions that modify a string argument or
97 * return a constant string that must not be freed.
99 #define G_STR_DELIMITERS "_-|> <."
100 gchar* g_strdelimit (gchar *string,
101 const gchar *delimiters,
102 gchar new_delimiter);
103 gchar* g_strcanon (gchar *string,
104 const gchar *valid_chars,
105 gchar substitutor);
106 G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST;
107 G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST;
108 gchar* g_strreverse (gchar *string);
109 gsize g_strlcpy (gchar *dest,
110 const gchar *src,
111 gsize dest_size);
112 gsize g_strlcat (gchar *dest,
113 const gchar *src,
114 gsize dest_size);
115 gchar * g_strstr_len (const gchar *haystack,
116 gssize haystack_len,
117 const gchar *needle);
118 gchar * g_strrstr (const gchar *haystack,
119 const gchar *needle);
120 gchar * g_strrstr_len (const gchar *haystack,
121 gssize haystack_len,
122 const gchar *needle);
124 gboolean g_str_has_suffix (const gchar *str,
125 const gchar *suffix);
126 gboolean g_str_has_prefix (const gchar *str,
127 const gchar *prefix);
129 /* String to/from double conversion functions */
131 gdouble g_strtod (const gchar *nptr,
132 gchar **endptr);
133 gdouble g_ascii_strtod (const gchar *nptr,
134 gchar **endptr);
135 guint64 g_ascii_strtoull (const gchar *nptr,
136 gchar **endptr,
137 guint base);
138 gint64 g_ascii_strtoll (const gchar *nptr,
139 gchar **endptr,
140 guint base);
141 /* 29 bytes should enough for all possible values that
142 * g_ascii_dtostr can produce.
143 * Then add 10 for good measure */
144 #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
145 gchar * g_ascii_dtostr (gchar *buffer,
146 gint buf_len,
147 gdouble d);
148 gchar * g_ascii_formatd (gchar *buffer,
149 gint buf_len,
150 const gchar *format,
151 gdouble d);
153 /* removes leading spaces */
154 gchar* g_strchug (gchar *string);
155 /* removes trailing spaces */
156 gchar* g_strchomp (gchar *string);
157 /* removes leading & trailing spaces */
158 #define g_strstrip( string ) g_strchomp (g_strchug (string))
160 gint g_ascii_strcasecmp (const gchar *s1,
161 const gchar *s2);
162 gint g_ascii_strncasecmp (const gchar *s1,
163 const gchar *s2,
164 gsize n);
165 gchar* g_ascii_strdown (const gchar *str,
166 gssize len) G_GNUC_MALLOC;
167 gchar* g_ascii_strup (const gchar *str,
168 gssize len) G_GNUC_MALLOC;
170 #ifndef G_DISABLE_DEPRECATED
172 /* The following four functions are deprecated and will be removed in
173 * the next major release. They use the locale-specific tolower and
174 * toupper, which is almost never the right thing.
177 gint g_strcasecmp (const gchar *s1,
178 const gchar *s2);
179 gint g_strncasecmp (const gchar *s1,
180 const gchar *s2,
181 guint n);
182 gchar* g_strdown (gchar *string);
183 gchar* g_strup (gchar *string);
185 #endif /* G_DISABLE_DEPRECATED */
187 /* String utility functions that return a newly allocated string which
188 * ought to be freed with g_free from the caller at some point.
190 gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
191 gchar* g_strdup_printf (const gchar *format,
192 ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
193 gchar* g_strdup_vprintf (const gchar *format,
194 va_list args) G_GNUC_MALLOC;
195 gchar* g_strndup (const gchar *str,
196 gsize n) G_GNUC_MALLOC;
197 gchar* g_strnfill (gsize length,
198 gchar fill_char) G_GNUC_MALLOC;
199 gchar* g_strconcat (const gchar *string1,
200 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
201 gchar* g_strjoin (const gchar *separator,
202 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
204 /* Make a copy of a string interpreting C string -style escape
205 * sequences. Inverse of g_strescape. The recognized sequences are \b
206 * \f \n \r \t \\ \" and the octal format.
208 gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
210 /* Copy a string escaping nonprintable characters like in C strings.
211 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
212 * to a string containing characters that are not to be escaped.
214 * Deprecated API: gchar* g_strescape (const gchar *source);
215 * Luckily this function wasn't used much, using NULL as second parameter
216 * provides mostly identical semantics.
218 gchar* g_strescape (const gchar *source,
219 const gchar *exceptions) G_GNUC_MALLOC;
221 gpointer g_memdup (gconstpointer mem,
222 guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
224 /* NULL terminated string arrays.
225 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
226 * at delim and return a newly allocated string array.
227 * g_strjoinv() concatenates all of str_array's strings, sliding in an
228 * optional separator, the returned string is newly allocated.
229 * g_strfreev() frees the array itself and all of its strings.
230 * g_strdupv() copies a NULL-terminated array of strings
231 * g_strv_length() returns the length of a NULL-terminated array of strings
233 gchar** g_strsplit (const gchar *string,
234 const gchar *delimiter,
235 gint max_tokens) G_GNUC_MALLOC;
236 gchar ** g_strsplit_set (const gchar *string,
237 const gchar *delimiters,
238 gint max_tokens) G_GNUC_MALLOC;
239 gchar* g_strjoinv (const gchar *separator,
240 gchar **str_array) G_GNUC_MALLOC;
241 void g_strfreev (gchar **str_array);
242 gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC;
243 guint g_strv_length (gchar **str_array);
245 gchar* g_stpcpy (gchar *dest,
246 const char *src);
248 G_CONST_RETURN gchar *g_strip_context (const gchar *msgid,
249 const gchar *msgval) G_GNUC_FORMAT(1);
251 G_CONST_RETURN gchar *g_dgettext (const gchar *domain,
252 const gchar *msgid) G_GNUC_FORMAT(2);
254 G_CONST_RETURN gchar *g_dngettext (const gchar *domain,
255 const gchar *msgid,
256 const gchar *msgid_plural,
257 gulong n) G_GNUC_FORMAT(3);
258 G_CONST_RETURN gchar *g_dpgettext (const gchar *domain,
259 const gchar *msgctxtid,
260 gsize msgidoffset) G_GNUC_FORMAT(2);
261 G_CONST_RETURN gchar *g_dpgettext2 (const gchar *domain,
262 const gchar *context,
263 const gchar *msgid) G_GNUC_FORMAT(3);
265 G_END_DECLS
267 #endif /* __G_STRFUNCS_H__ */