Don't use G_DISABLE_DEPRECATED guards around deprecated functions
[platform/upstream/glib.git] / glib / gstrfuncs.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/.
25  */
26
27 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
30
31 #ifndef __G_STRFUNCS_H__
32 #define __G_STRFUNCS_H__
33
34 #include <stdarg.h>
35 #include <glib/gmacros.h>
36 #include <glib/gtypes.h>
37
38 G_BEGIN_DECLS
39
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;
54
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 gchar                 g_ascii_tolower  (gchar        c) G_GNUC_CONST;
91 gchar                 g_ascii_toupper  (gchar        c) G_GNUC_CONST;
92
93 gint                  g_ascii_digit_value  (gchar    c) G_GNUC_CONST;
94 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 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 const gchar *         g_strerror       (gint          errnum) G_GNUC_CONST;
107 const 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);
123
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);
128
129 /* String to/from double conversion functions */
130
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);
152
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))
159
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;
169
170
171 GLIB_DEPRECATED
172 gint                  g_strcasecmp     (const gchar *s1,
173                                         const gchar *s2);
174 GLIB_DEPRECATED
175 gint                  g_strncasecmp    (const gchar *s1,
176                                         const gchar *s2,
177                                         guint        n);
178 GLIB_DEPRECATED
179 gchar*                g_strdown        (gchar       *string);
180 GLIB_DEPRECATED
181 gchar*                g_strup          (gchar       *string);
182
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 gchar*                g_strdup         (const gchar *str) G_GNUC_MALLOC;
188 gchar*                g_strdup_printf  (const gchar *format,
189                                         ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
190 gchar*                g_strdup_vprintf (const gchar *format,
191                                         va_list      args) G_GNUC_MALLOC;
192 gchar*                g_strndup        (const gchar *str,
193                                         gsize        n) G_GNUC_MALLOC;  
194 gchar*                g_strnfill       (gsize        length,  
195                                         gchar        fill_char) G_GNUC_MALLOC;
196 gchar*                g_strconcat      (const gchar *string1,
197                                         ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
198 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 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 gchar*                g_strescape      (const gchar *source,
216                                         const gchar *exceptions) G_GNUC_MALLOC;
217
218 gpointer              g_memdup         (gconstpointer mem,
219                                         guint          byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
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 gchar**               g_strsplit       (const gchar  *string,
231                                         const gchar  *delimiter,
232                                         gint          max_tokens) G_GNUC_MALLOC;
233 gchar **              g_strsplit_set   (const gchar *string,
234                                         const gchar *delimiters,
235                                         gint         max_tokens) G_GNUC_MALLOC;
236 gchar*                g_strjoinv       (const gchar  *separator,
237                                         gchar       **str_array) G_GNUC_MALLOC;
238 void                  g_strfreev       (gchar       **str_array);
239 gchar**               g_strdupv        (gchar       **str_array) G_GNUC_MALLOC;
240 guint                 g_strv_length    (gchar       **str_array);
241
242 gchar*                g_stpcpy         (gchar        *dest,
243                                         const char   *src);
244
245 G_END_DECLS
246
247 #endif /* __G_STRFUNCS_H__ */