gstrfuncs.h

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

Copyright © Nokia Corporation 2001-2008
Back to top