williamr@2: /* GLIB - Library of useful routines for C programming williamr@2: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald williamr@2: * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. williamr@2: * williamr@2: * This library is free software; you can redistribute it and/or williamr@2: * modify it under the terms of the GNU Lesser General Public williamr@2: * License as published by the Free Software Foundation; either williamr@2: * version 2 of the License, or (at your option) any later version. williamr@2: * williamr@2: * This library is distributed in the hope that it will be useful, williamr@2: * but WITHOUT ANY WARRANTY; without even the implied warranty of williamr@2: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU williamr@2: * Lesser General Public License for more details. williamr@2: * williamr@2: * You should have received a copy of the GNU Lesser General Public williamr@2: * License along with this library; if not, write to the williamr@2: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, williamr@2: * Boston, MA 02111-1307, USA. williamr@2: */ williamr@2: williamr@2: /* williamr@2: * Modified by the GLib Team and others 1997-2000. See the AUTHORS williamr@2: * file for a list of people on the GLib Team. See the ChangeLog williamr@2: * files for a list of changes. These files are distributed with williamr@2: * GLib at ftp://ftp.gtk.org/pub/gtk/. williamr@2: */ williamr@2: williamr@2: #ifndef __G_STRFUNCS_H__ williamr@2: #define __G_STRFUNCS_H__ williamr@2: williamr@2: #include <_ansi.h> williamr@2: #include williamr@2: #include williamr@2: williamr@2: G_BEGIN_DECLS williamr@2: williamr@2: /* Functions like the ones in that are not affected by locale. */ williamr@2: typedef enum { williamr@2: G_ASCII_ALNUM = 1 << 0, williamr@2: G_ASCII_ALPHA = 1 << 1, williamr@2: G_ASCII_CNTRL = 1 << 2, williamr@2: G_ASCII_DIGIT = 1 << 3, williamr@2: G_ASCII_GRAPH = 1 << 4, williamr@2: G_ASCII_LOWER = 1 << 5, williamr@2: G_ASCII_PRINT = 1 << 6, williamr@2: G_ASCII_PUNCT = 1 << 7, williamr@2: G_ASCII_SPACE = 1 << 8, williamr@2: G_ASCII_UPPER = 1 << 9, williamr@2: G_ASCII_XDIGIT = 1 << 10 williamr@2: } GAsciiType; williamr@2: williamr@2: #ifdef __SYMBIAN32__ williamr@2: IMPORT_C const guint16 * const * _g_ascii_table(); williamr@2: #endif /* __SYMBIAN32__ */ williamr@2: GLIB_VAR const guint16 * const g_ascii_table; williamr@2: williamr@2: #define g_ascii_isalnum(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0) williamr@2: williamr@2: #define g_ascii_isalpha(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0) williamr@2: williamr@2: #define g_ascii_iscntrl(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0) williamr@2: williamr@2: #define g_ascii_isdigit(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0) williamr@2: williamr@2: #define g_ascii_isgraph(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0) williamr@2: williamr@2: #define g_ascii_islower(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0) williamr@2: williamr@2: #define g_ascii_isprint(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0) williamr@2: williamr@2: #define g_ascii_ispunct(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0) williamr@2: williamr@2: #define g_ascii_isspace(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0) williamr@2: williamr@2: #define g_ascii_isupper(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0) williamr@2: williamr@2: #define g_ascii_isxdigit(c) \ williamr@2: ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0) williamr@2: williamr@2: IMPORT_C gchar g_ascii_tolower (gchar c) G_GNUC_CONST; williamr@2: IMPORT_C gchar g_ascii_toupper (gchar c) G_GNUC_CONST; williamr@2: williamr@2: IMPORT_C gint g_ascii_digit_value (gchar c) G_GNUC_CONST; williamr@2: IMPORT_C gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST; williamr@2: williamr@2: /* String utility functions that modify a string argument or williamr@2: * return a constant string that must not be freed. williamr@2: */ williamr@2: #define G_STR_DELIMITERS "_-|> <." williamr@2: IMPORT_C gchar* g_strdelimit (gchar *string, williamr@2: const gchar *delimiters, williamr@2: gchar new_delimiter); williamr@2: IMPORT_C gchar* g_strcanon (gchar *string, williamr@2: const gchar *valid_chars, williamr@2: gchar substitutor); williamr@2: IMPORT_C G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST; williamr@2: IMPORT_C G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST; williamr@2: IMPORT_C gchar* g_strreverse (gchar *string); williamr@2: IMPORT_C gsize g_strlcpy (gchar *dest, williamr@2: const gchar *src, williamr@2: gsize dest_size); williamr@2: IMPORT_C gsize g_strlcat (gchar *dest, williamr@2: const gchar *src, williamr@2: gsize dest_size); williamr@2: IMPORT_C gchar * g_strstr_len (const gchar *haystack, williamr@2: gssize haystack_len, williamr@2: const gchar *needle); williamr@2: IMPORT_C gchar * g_strrstr (const gchar *haystack, williamr@2: const gchar *needle); williamr@2: IMPORT_C gchar * g_strrstr_len (const gchar *haystack, williamr@2: gssize haystack_len, williamr@2: const gchar *needle); williamr@2: williamr@2: IMPORT_C gboolean g_str_has_suffix (const gchar *str, williamr@2: const gchar *suffix); williamr@2: IMPORT_C gboolean g_str_has_prefix (const gchar *str, williamr@2: const gchar *prefix); williamr@2: williamr@2: /* String to/from double conversion functions */ williamr@2: williamr@2: IMPORT_C gdouble g_strtod (const gchar *nptr, williamr@2: gchar **endptr); williamr@2: IMPORT_C gdouble g_ascii_strtod (const gchar *nptr, williamr@2: gchar **endptr); williamr@2: IMPORT_C guint64 g_ascii_strtoull (const gchar *nptr, williamr@2: gchar **endptr, williamr@2: guint base); williamr@2: /* 29 bytes should enough for all possible values that williamr@2: * g_ascii_dtostr can produce. williamr@2: * Then add 10 for good measure */ williamr@2: #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10) williamr@2: IMPORT_C gchar * g_ascii_dtostr (gchar *buffer, williamr@2: gint buf_len, williamr@2: gdouble d); williamr@2: IMPORT_C gchar * g_ascii_formatd (gchar *buffer, williamr@2: gint buf_len, williamr@2: const gchar *format, williamr@2: gdouble d); williamr@2: williamr@2: /* removes leading spaces */ williamr@2: IMPORT_C gchar* g_strchug (gchar *string); williamr@2: /* removes trailing spaces */ williamr@2: IMPORT_C gchar* g_strchomp (gchar *string); williamr@2: /* removes leading & trailing spaces */ williamr@2: #define g_strstrip( string ) g_strchomp (g_strchug (string)) williamr@2: williamr@2: IMPORT_C gint g_ascii_strcasecmp (const gchar *s1, williamr@2: const gchar *s2); williamr@2: IMPORT_C gint g_ascii_strncasecmp (const gchar *s1, williamr@2: const gchar *s2, williamr@2: gsize n); williamr@2: IMPORT_C gchar* g_ascii_strdown (const gchar *str, williamr@2: gssize len) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_ascii_strup (const gchar *str, williamr@2: gssize len) G_GNUC_MALLOC; williamr@2: williamr@2: #ifndef G_DISABLE_DEPRECATED williamr@2: williamr@2: /* The following four functions are deprecated and will be removed in williamr@2: * the next major release. They use the locale-specific tolower and williamr@2: * toupper, which is almost never the right thing. williamr@2: */ williamr@2: williamr@2: IMPORT_C gint g_strcasecmp (const gchar *s1, williamr@2: const gchar *s2); williamr@2: IMPORT_C gint g_strncasecmp (const gchar *s1, williamr@2: const gchar *s2, williamr@2: guint n); williamr@2: IMPORT_C gchar* g_strdown (gchar *string); williamr@2: IMPORT_C gchar* g_strup (gchar *string); williamr@2: williamr@2: #endif /* G_DISABLE_DEPRECATED */ williamr@2: williamr@2: /* String utility functions that return a newly allocated string which williamr@2: * ought to be freed with g_free from the caller at some point. williamr@2: */ williamr@2: IMPORT_C gchar* g_strdup (const gchar *str) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strdup_printf (const gchar *format, williamr@2: ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strdup_vprintf (const gchar *format, williamr@2: va_list args) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strndup (const gchar *str, williamr@2: gsize n) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strnfill (gsize length, williamr@2: gchar fill_char) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strconcat (const gchar *string1, williamr@2: ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; williamr@2: IMPORT_C gchar* g_strjoin (const gchar *separator, williamr@2: ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; williamr@2: williamr@2: /* Make a copy of a string interpreting C string -style escape williamr@2: * sequences. Inverse of g_strescape. The recognized sequences are \b williamr@2: * \f \n \r \t \\ \" and the octal format. williamr@2: */ williamr@2: IMPORT_C gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC; williamr@2: williamr@2: /* Copy a string escaping nonprintable characters like in C strings. williamr@2: * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points williamr@2: * to a string containing characters that are not to be escaped. williamr@2: * williamr@2: * Deprecated API: gchar* g_strescape (const gchar *source); williamr@2: * Luckily this function wasn't used much, using NULL as second parameter williamr@2: * provides mostly identical semantics. williamr@2: */ williamr@2: IMPORT_C gchar* g_strescape (const gchar *source, williamr@2: const gchar *exceptions) G_GNUC_MALLOC; williamr@2: williamr@2: IMPORT_C gpointer g_memdup (gconstpointer mem, williamr@2: guint byte_size) G_GNUC_MALLOC; williamr@2: williamr@2: /* NULL terminated string arrays. williamr@2: * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens williamr@2: * at delim and return a newly allocated string array. williamr@2: * g_strjoinv() concatenates all of str_array's strings, sliding in an williamr@2: * optional separator, the returned string is newly allocated. williamr@2: * g_strfreev() frees the array itself and all of its strings. williamr@2: * g_strdupv() copies a NULL-terminated array of strings williamr@2: * g_strv_length() returns the length of a NULL-terminated array of strings williamr@2: */ williamr@2: IMPORT_C gchar** g_strsplit (const gchar *string, williamr@2: const gchar *delimiter, williamr@2: gint max_tokens) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar ** g_strsplit_set (const gchar *string, williamr@2: const gchar *delimiters, williamr@2: gint max_tokens) G_GNUC_MALLOC; williamr@2: IMPORT_C gchar* g_strjoinv (const gchar *separator, williamr@2: gchar **str_array) G_GNUC_MALLOC; williamr@2: IMPORT_C void g_strfreev (gchar **str_array); williamr@2: IMPORT_C gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC; williamr@2: IMPORT_C guint g_strv_length (gchar **str_array); williamr@2: williamr@2: IMPORT_C gchar* g_stpcpy (gchar *dest, williamr@2: const char *src); williamr@2: williamr@2: IMPORT_C G_CONST_RETURN gchar *g_strip_context (const gchar *msgid, williamr@2: const gchar *msgval); williamr@2: williamr@2: G_END_DECLS williamr@2: williamr@2: #endif /* __G_STRFUNCS_H__ */