intial implementation of new API functions. Not sure if it behaves as
[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 #ifndef __G_STRFUNCS_H__
28 #define __G_STRFUNCS_H__
29
30 #include <stdarg.h>
31 #include <glib/gtypes.h>
32
33 G_BEGIN_DECLS
34
35 /* Functions like the ones in <ctype.h> that are not affected by locale. */
36 gboolean              g_ascii_isalpha  (gchar        c) G_GNUC_CONST;
37 gboolean              g_ascii_isalnum  (gchar        c) G_GNUC_CONST;
38 gboolean              g_ascii_islower  (gchar        c) G_GNUC_CONST;
39 gboolean              g_ascii_isupper  (gchar        c) G_GNUC_CONST;
40 gchar                 g_ascii_tolower  (gchar        c) G_GNUC_CONST;
41 gchar                 g_ascii_toupper  (gchar        c) G_GNUC_CONST;
42
43 /* String utility functions that modify a string argument or
44  * return a constant string that must not be freed.
45  */
46 #define  G_STR_DELIMITERS       "_-|> <."
47 gchar*                g_strdelimit     (gchar        *string,
48                                         const gchar *delimiters,
49                                         gchar         new_delimiter);
50 gchar*                g_strcanon       (gchar       *string,
51                                         const gchar *valid_chars,
52                                         gchar        substitutor);
53 gdouble               g_strtod         (const gchar *nptr,
54                                         gchar       **endptr);
55 G_CONST_RETURN gchar* g_strerror       (gint          errnum) G_GNUC_CONST;
56 G_CONST_RETURN gchar* g_strsignal      (gint          signum) G_GNUC_CONST;
57 gchar*                g_strreverse     (gchar        *string);
58 gsize                 g_strlcpy        (gchar        *dest,
59                                         const gchar  *src,
60                                         gsize         dest_size);
61 gsize                 g_strlcat        (gchar        *dest,
62                                         const gchar  *src,
63                                         gsize         dest_size);
64 gchar *               g_strstr_len     (const gchar  *haystack,
65                                         gssize        haystack_len,
66                                         const gchar  *needle);
67 gchar *               g_strrstr        (const gchar  *haystack,
68                                         const gchar  *needle);
69 gchar *               g_strrstr_len    (const gchar  *haystack,
70                                         gssize        haystack_len,
71                                         const gchar  *needle);
72
73 /* removes leading spaces */
74 gchar*                g_strchug        (gchar        *string);
75 /* removes trailing spaces */
76 gchar*                g_strchomp       (gchar        *string);
77 /* removes leading & trailing spaces */
78 #define g_strstrip( string )    g_strchomp (g_strchug (string))
79
80 gint                  g_ascii_strcasecmp  (const gchar *s1,
81                                            const gchar *s2);
82 gint                  g_ascii_strncasecmp (const gchar *s1,
83                                            const gchar *s2,
84                                            guint        n);
85 gchar*                g_ascii_strdown     (const gchar *string);
86 gchar*                g_ascii_strup       (const gchar *string);
87
88 #ifndef G_DISABLE_DEPRECATED
89
90 /* The following four functions are deprecated and will be removed in
91  * the next major release. They use the locale-specific tolower and
92  * toupper, which is almost never the right thing.
93  */
94
95 gint                  g_strcasecmp     (const gchar *s1,
96                                         const gchar *s2);
97 gint                  g_strncasecmp    (const gchar *s1,
98                                         const gchar *s2,
99                                         guint        n);
100 gchar*                g_strdown        (gchar        *string);
101 gchar*                g_strup          (gchar        *string);
102
103 #endif /* G_DISABLE_DEPRECATED */
104
105 /* String utility functions that return a newly allocated string which
106  * ought to be freed with g_free from the caller at some point.
107  */
108 gchar*                g_strdup         (const gchar *str);
109 gchar*                g_strdup_printf  (const gchar *format,
110                                         ...) G_GNUC_PRINTF (1, 2);
111 gchar*                g_strdup_vprintf (const gchar *format,
112                                         va_list      args);
113 gchar*                g_strndup        (const gchar *str,
114                                         gsize        n);  
115 gchar*                g_strnfill       (gsize        length,  
116                                         gchar        fill_char);
117 gchar*                g_strconcat      (const gchar *string1,
118                                         ...); /* NULL terminated */
119 gchar*                g_strjoin        (const gchar  *separator,
120                                         ...); /* NULL terminated */
121 /* Make a copy of a string interpreting C string -style escape
122  * sequences. Inverse of g_strescape. The recognized sequences are \b
123  * \f \n \r \t \\ \" and the octal format.
124  */
125 gchar*                g_strcompress    (const gchar *source);
126
127 /* Copy a string escaping nonprintable characters like in C strings.
128  * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
129  * to a string containing characters that are not to be escaped.
130  *
131  * Deprecated API: gchar* g_strescape (const gchar *source);
132  * Luckily this function wasn't used much, using NULL as second parameter
133  * provides mostly identical semantics.
134  */
135 gchar*                g_strescape      (const gchar *source,
136                                         const gchar *exceptions);
137
138 gpointer              g_memdup         (gconstpointer mem,
139                                         guint          byte_size);
140
141 /* NULL terminated string arrays.
142  * g_strsplit() splits up string into max_tokens tokens at delim and
143  * returns a newly allocated string array.
144  * g_strjoinv() concatenates all of str_array's strings, sliding in an
145  * optional separator, the returned string is newly allocated.
146  * g_strfreev() frees the array itself and all of its strings.
147  * g_strdupv() copies a NULL-terminated array of strings
148  */
149 gchar**               g_strsplit       (const gchar  *string,
150                                         const gchar  *delimiter,
151                                         gint          max_tokens);
152 gchar*                g_strjoinv       (const gchar  *separator,
153                                         gchar       **str_array);
154 void                  g_strfreev       (gchar       **str_array);
155 gchar**               g_strdupv        (gchar       **str_array);
156
157 gchar*                g_stpcpy         (gchar        *dest,
158                                         const char   *src);
159
160 G_END_DECLS
161
162 #endif /* __G_STRFUNCS_H__ */