628b3b16632b126b4bdedb7285a7d0845989bbef
[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 /* String utility functions that modify a string argument or
36  * return a constant string that must not be freed.
37  */
38 #define  G_STR_DELIMITERS       "_-|> <."
39 gchar*                g_strdelimit     (gchar        *string,
40                                         const gchar *delimiters,
41                                         gchar         new_delimiter);
42 gchar*                g_strcanon       (gchar       *string,
43                                         const gchar *valid_chars,
44                                         gchar        substitutor);
45 gdouble               g_strtod         (const gchar *nptr,
46                                         gchar       **endptr);
47 G_CONST_RETURN gchar* g_strerror       (gint          errnum) G_GNUC_CONST;
48 G_CONST_RETURN gchar* g_strsignal      (gint          signum) G_GNUC_CONST;
49 gint                  g_strcasecmp     (const gchar *s1,  
50                                         const gchar *s2);
51 gint                  g_strncasecmp    (const gchar *s1,  
52                                         const gchar *s2,
53                                         gsize        n);    
54 gchar*                g_strdown        (gchar        *string);
55 gchar*                g_strup          (gchar        *string);
56 gchar*                g_strreverse     (gchar        *string);
57 gsize                 g_strlcpy        (gchar        *dest,
58                                         const gchar  *src,
59                                         gsize         dest_size);
60 gsize                 g_strlcat        (gchar        *dest,
61                                         const gchar  *src,
62                                         gsize         dest_size);
63 gchar *               g_strstr_len     (const gchar  *haystack,
64                                         gssize        haystack_len,
65                                         const gchar  *needle);
66 gchar *               g_strrstr        (const gchar  *haystack,
67                                         const gchar  *needle);
68 gchar *               g_strrstr_len    (const gchar  *haystack,
69                                         gssize        haystack_len,
70                                         const gchar  *needle);
71
72 /* removes leading spaces */
73 gchar*                g_strchug        (gchar        *string);
74 /* removes trailing spaces */
75 gchar*                g_strchomp       (gchar        *string);
76 /* removes leading & trailing spaces */
77 #define g_strstrip( string )    g_strchomp (g_strchug (string))
78
79 /* String utility functions that return a newly allocated string which
80  * ought to be freed with g_free from the caller at some point.
81  */
82 gchar*                g_strdup         (const gchar *str);
83 gchar*                g_strdup_printf  (const gchar *format,
84                                         ...) G_GNUC_PRINTF (1, 2);
85 gchar*                g_strdup_vprintf (const gchar *format,
86                                         va_list      args);
87 gchar*                g_strndup        (const gchar *str,
88                                         gsize        n);  
89 gchar*                g_strnfill       (gsize        length,  
90                                         gchar        fill_char);
91 gchar*                g_strconcat      (const gchar *string1,
92                                         ...); /* NULL terminated */
93 gchar*                g_strjoin        (const gchar  *separator,
94                                         ...); /* NULL terminated */
95 /* Make a copy of a string interpreting C string -style escape
96  * sequences. Inverse of g_strescape. The recognized sequences are \b
97  * \f \n \r \t \\ \" and the octal format.
98  */
99 gchar*                g_strcompress    (const gchar *source);
100
101 /* Copy a string escaping nonprintable characters like in C strings.
102  * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
103  * to a string containing characters that are not to be escaped.
104  *
105  * Deprecated API: gchar* g_strescape (const gchar *source);
106  * Luckily this function wasn't used much, using NULL as second parameter
107  * provides mostly identical semantics.
108  */
109 gchar*                g_strescape      (const gchar *source,
110                                         const gchar *exceptions);
111
112 gpointer              g_memdup         (gconstpointer mem,
113                                         guint          byte_size);
114
115 /* NULL terminated string arrays.
116  * g_strsplit() splits up string into max_tokens tokens at delim and
117  * returns a newly allocated string array.
118  * g_strjoinv() concatenates all of str_array's strings, sliding in an
119  * optional separator, the returned string is newly allocated.
120  * g_strfreev() frees the array itself and all of its strings.
121  * g_strdupv() copies a NULL-terminated array of strings
122  */
123 gchar**               g_strsplit       (const gchar  *string,
124                                         const gchar  *delimiter,
125                                         gint          max_tokens);
126 gchar*                g_strjoinv       (const gchar  *separator,
127                                         gchar       **str_array);
128 void                  g_strfreev       (gchar       **str_array);
129 gchar**               g_strdupv        (gchar       **str_array);
130
131 gchar*                g_stpcpy         (gchar        *dest,
132                                         const char   *src);
133
134 G_END_DECLS
135
136 #endif /* __G_STRFUNCS_H__ */