Navit SVN

/work/compile/navit/src/navit/support/glib/gstrfuncs.h

00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/.
00025  */
00026 
00027 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
00028 #error "Only <glib.h> can be included directly."
00029 #endif
00030 
00031 #ifndef __G_STRFUNCS_H__
00032 #define __G_STRFUNCS_H__
00033 
00034 #include <stdarg.h>
00035 #include <glib/gtypes.h>
00036 
00037 G_BEGIN_DECLS
00038 
00039 /* Functions like the ones in <ctype.h> that are not affected by locale. */
00040 typedef enum {
00041   G_ASCII_ALNUM  = 1 << 0,
00042   G_ASCII_ALPHA  = 1 << 1,
00043   G_ASCII_CNTRL  = 1 << 2,
00044   G_ASCII_DIGIT  = 1 << 3,
00045   G_ASCII_GRAPH  = 1 << 4,
00046   G_ASCII_LOWER  = 1 << 5,
00047   G_ASCII_PRINT  = 1 << 6,
00048   G_ASCII_PUNCT  = 1 << 7,
00049   G_ASCII_SPACE  = 1 << 8,
00050   G_ASCII_UPPER  = 1 << 9,
00051   G_ASCII_XDIGIT = 1 << 10
00052 } GAsciiType;
00053 
00054 GLIB_VAR const guint16 * const g_ascii_table;
00055 
00056 #define g_ascii_isalnum(c) \
00057   ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
00058 
00059 #define g_ascii_isalpha(c) \
00060   ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
00061 
00062 #define g_ascii_iscntrl(c) \
00063   ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
00064 
00065 #define g_ascii_isdigit(c) \
00066   ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
00067 
00068 #define g_ascii_isgraph(c) \
00069   ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
00070 
00071 #define g_ascii_islower(c) \
00072   ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
00073 
00074 #define g_ascii_isprint(c) \
00075   ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
00076 
00077 #define g_ascii_ispunct(c) \
00078   ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
00079 
00080 #define g_ascii_isspace(c) \
00081   ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
00082 
00083 #define g_ascii_isupper(c) \
00084   ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
00085 
00086 #define g_ascii_isxdigit(c) \
00087   ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
00088 
00089 gchar                 g_ascii_tolower  (gchar        c) G_GNUC_CONST;
00090 gchar                 g_ascii_toupper  (gchar        c) G_GNUC_CONST;
00091 
00092 gint                  g_ascii_digit_value  (gchar    c) G_GNUC_CONST;
00093 gint                  g_ascii_xdigit_value (gchar    c) G_GNUC_CONST;
00094 
00095 /* String utility functions that modify a string argument or
00096  * return a constant string that must not be freed.
00097  */
00098 #define  G_STR_DELIMITERS       "_-|> <."
00099 gchar*                g_strdelimit     (gchar        *string,
00100                                         const gchar  *delimiters,
00101                                         gchar         new_delimiter);
00102 gchar*                g_strcanon       (gchar        *string,
00103                                         const gchar  *valid_chars,
00104                                         gchar         substitutor);
00105 G_CONST_RETURN gchar* g_strerror       (gint          errnum) G_GNUC_CONST;
00106 G_CONST_RETURN gchar* g_strsignal      (gint          signum) G_GNUC_CONST;
00107 gchar*                g_strreverse     (gchar        *string);
00108 gsize                 g_strlcpy        (gchar        *dest,
00109                                         const gchar  *src,
00110                                         gsize         dest_size);
00111 gsize                 g_strlcat        (gchar        *dest,
00112                                         const gchar  *src,
00113                                         gsize         dest_size);
00114 gchar *               g_strstr_len     (const gchar  *haystack,
00115                                         gssize        haystack_len,
00116                                         const gchar  *needle);
00117 gchar *               g_strrstr        (const gchar  *haystack,
00118                                         const gchar  *needle);
00119 gchar *               g_strrstr_len    (const gchar  *haystack,
00120                                         gssize        haystack_len,
00121                                         const gchar  *needle);
00122 
00123 gboolean              g_str_has_suffix (const gchar  *str,
00124                                         const gchar  *suffix);
00125 gboolean              g_str_has_prefix (const gchar  *str,
00126                                         const gchar  *prefix);
00127 
00128 /* String to/from double conversion functions */
00129 
00130 gdouble               g_strtod         (const gchar  *nptr,
00131                                         gchar       **endptr);
00132 gdouble               g_ascii_strtod   (const gchar  *nptr,
00133                                         gchar       **endptr);
00134 guint64               g_ascii_strtoull (const gchar *nptr,
00135                                         gchar      **endptr,
00136                                         guint        base);
00137 gint64                g_ascii_strtoll  (const gchar *nptr,
00138                                         gchar      **endptr,
00139                                         guint        base);
00140 /* 29 bytes should enough for all possible values that
00141  * g_ascii_dtostr can produce.
00142  * Then add 10 for good measure */
00143 #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
00144 gchar *               g_ascii_dtostr   (gchar        *buffer,
00145                                         gint          buf_len,
00146                                         gdouble       d);
00147 gchar *               g_ascii_formatd  (gchar        *buffer,
00148                                         gint          buf_len,
00149                                         const gchar  *format,
00150                                         gdouble       d);
00151 
00152 /* removes leading spaces */
00153 gchar*                g_strchug        (gchar        *string);
00154 /* removes trailing spaces */
00155 gchar*                g_strchomp       (gchar        *string);
00156 /* removes leading & trailing spaces */
00157 #define g_strstrip( string )    g_strchomp (g_strchug (string))
00158 
00159 gint                  g_ascii_strcasecmp  (const gchar *s1,
00160                                            const gchar *s2);
00161 gint                  g_ascii_strncasecmp (const gchar *s1,
00162                                            const gchar *s2,
00163                                            gsize        n);
00164 gchar*                g_ascii_strdown     (const gchar *str,
00165                                            gssize       len) G_GNUC_MALLOC;
00166 gchar*                g_ascii_strup       (const gchar *str,
00167                                            gssize       len) G_GNUC_MALLOC;
00168 
00169 #ifndef G_DISABLE_DEPRECATED
00170 
00171 /* The following four functions are deprecated and will be removed in
00172  * the next major release. They use the locale-specific tolower and
00173  * toupper, which is almost never the right thing.
00174  */
00175 
00176 gint                  g_strcasecmp     (const gchar *s1,
00177                                         const gchar *s2);
00178 gint                  g_strncasecmp    (const gchar *s1,
00179                                         const gchar *s2,
00180                                         guint        n);
00181 gchar*                g_strdown        (gchar        *string);
00182 gchar*                g_strup          (gchar        *string);
00183 
00184 #endif /* G_DISABLE_DEPRECATED */
00185 
00186 /* String utility functions that return a newly allocated string which
00187  * ought to be freed with g_free from the caller at some point.
00188  */
00189 gchar*                g_strdup         (const gchar *str) G_GNUC_MALLOC;
00190 gchar*                g_strdup_printf  (const gchar *format,
00191                                         ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
00192 gchar*                g_strdup_vprintf (const gchar *format,
00193                                         va_list      args) G_GNUC_MALLOC;
00194 gchar*                g_strndup        (const gchar *str,
00195                                         gsize        n) G_GNUC_MALLOC;  
00196 gchar*                g_strnfill       (gsize        length,  
00197                                         gchar        fill_char) G_GNUC_MALLOC;
00198 gchar*                g_strconcat      (const gchar *string1,
00199                                         ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
00200 gchar*                g_strjoin        (const gchar  *separator,
00201                                         ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
00202 
00203 /* Make a copy of a string interpreting C string -style escape
00204  * sequences. Inverse of g_strescape. The recognized sequences are \b
00205  * \f \n \r \t \\ \" and the octal format.
00206  */
00207 gchar*                g_strcompress    (const gchar *source) G_GNUC_MALLOC;
00208 
00209 /* Copy a string escaping nonprintable characters like in C strings.
00210  * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
00211  * to a string containing characters that are not to be escaped.
00212  *
00213  * Deprecated API: gchar* g_strescape (const gchar *source);
00214  * Luckily this function wasn't used much, using NULL as second parameter
00215  * provides mostly identical semantics.
00216  */
00217 gchar*                g_strescape      (const gchar *source,
00218                                         const gchar *exceptions) G_GNUC_MALLOC;
00219 
00220 gpointer              g_memdup         (gconstpointer mem,
00221                                         guint          byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
00222 
00223 /* NULL terminated string arrays.
00224  * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
00225  * at delim and return a newly allocated string array.
00226  * g_strjoinv() concatenates all of str_array's strings, sliding in an
00227  * optional separator, the returned string is newly allocated.
00228  * g_strfreev() frees the array itself and all of its strings.
00229  * g_strdupv() copies a NULL-terminated array of strings
00230  * g_strv_length() returns the length of a NULL-terminated array of strings
00231  */
00232 gchar**               g_strsplit       (const gchar  *string,
00233                                         const gchar  *delimiter,
00234                                         gint          max_tokens) G_GNUC_MALLOC;
00235 gchar **              g_strsplit_set   (const gchar *string,
00236                                         const gchar *delimiters,
00237                                         gint         max_tokens) G_GNUC_MALLOC;
00238 gchar*                g_strjoinv       (const gchar  *separator,
00239                                         gchar       **str_array) G_GNUC_MALLOC;
00240 void                  g_strfreev       (gchar       **str_array);
00241 gchar**               g_strdupv        (gchar       **str_array) G_GNUC_MALLOC;
00242 guint                 g_strv_length    (gchar       **str_array);
00243 
00244 gchar*                g_stpcpy         (gchar        *dest,
00245                                         const char   *src);
00246 
00247 G_CONST_RETURN gchar *g_strip_context  (const gchar *msgid, 
00248                                         const gchar *msgval) G_GNUC_FORMAT(1);
00249 
00250 G_CONST_RETURN gchar *g_dgettext       (const gchar *domain,
00251                                         const gchar *msgid) G_GNUC_FORMAT(2);
00252 
00253 G_CONST_RETURN gchar *g_dngettext      (const gchar *domain,
00254                                         const gchar *msgid,
00255                                         const gchar *msgid_plural,
00256                                         gulong       n) G_GNUC_FORMAT(3);
00257 G_CONST_RETURN gchar *g_dpgettext      (const gchar *domain,
00258                                         const gchar *msgctxtid,
00259                                         gsize        msgidoffset) G_GNUC_FORMAT(2);
00260 G_CONST_RETURN gchar *g_dpgettext2     (const gchar *domain,
00261                                         const gchar *context,
00262                                         const gchar *msgid) G_GNUC_FORMAT(3);
00263 
00264 G_END_DECLS
00265 
00266 #endif /* __G_STRFUNCS_H__ */