Blame glib/gstrfuncs.h

Packit ae235b
/* GLIB - Library of useful routines for C programming
Packit ae235b
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit ae235b
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit ae235b
 * files for a list of changes.  These files are distributed with
Packit ae235b
 * GLib at ftp://ftp.gtk.org/pub/gtk/.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#ifndef __G_STRFUNCS_H__
Packit ae235b
#define __G_STRFUNCS_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
Packit ae235b
#error "Only <glib.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <stdarg.h>
Packit ae235b
#include <glib/gmacros.h>
Packit ae235b
#include <glib/gtypes.h>
Packit ae235b
#include <glib/gerror.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
/* Functions like the ones in <ctype.h> that are not affected by locale. */
Packit ae235b
typedef enum {
Packit ae235b
  G_ASCII_ALNUM  = 1 << 0,
Packit ae235b
  G_ASCII_ALPHA  = 1 << 1,
Packit ae235b
  G_ASCII_CNTRL  = 1 << 2,
Packit ae235b
  G_ASCII_DIGIT  = 1 << 3,
Packit ae235b
  G_ASCII_GRAPH  = 1 << 4,
Packit ae235b
  G_ASCII_LOWER  = 1 << 5,
Packit ae235b
  G_ASCII_PRINT  = 1 << 6,
Packit ae235b
  G_ASCII_PUNCT  = 1 << 7,
Packit ae235b
  G_ASCII_SPACE  = 1 << 8,
Packit ae235b
  G_ASCII_UPPER  = 1 << 9,
Packit ae235b
  G_ASCII_XDIGIT = 1 << 10
Packit ae235b
} GAsciiType;
Packit ae235b
Packit ae235b
GLIB_VAR const guint16 * const g_ascii_table;
Packit ae235b
Packit ae235b
#define g_ascii_isalnum(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isalpha(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_iscntrl(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isdigit(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isgraph(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_islower(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isprint(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_ispunct(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isspace(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isupper(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
Packit ae235b
Packit ae235b
#define g_ascii_isxdigit(c) \
Packit ae235b
  ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar                 g_ascii_tolower  (gchar        c) G_GNUC_CONST;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar                 g_ascii_toupper  (gchar        c) G_GNUC_CONST;
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint                  g_ascii_digit_value  (gchar    c) G_GNUC_CONST;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint                  g_ascii_xdigit_value (gchar    c) G_GNUC_CONST;
Packit ae235b
Packit ae235b
/* String utility functions that modify a string argument or
Packit ae235b
 * return a constant string that must not be freed.
Packit ae235b
 */
Packit ae235b
#define	 G_STR_DELIMITERS	"_-|> <."
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strdelimit     (gchar	     *string,
Packit ae235b
					const gchar  *delimiters,
Packit ae235b
					gchar	      new_delimiter);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strcanon       (gchar        *string,
Packit ae235b
					const gchar  *valid_chars,
Packit ae235b
					gchar         substitutor);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
const gchar *         g_strerror       (gint	      errnum) G_GNUC_CONST;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
const gchar *         g_strsignal      (gint	      signum) G_GNUC_CONST;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *	              g_strreverse     (gchar	     *string);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gsize	              g_strlcpy	       (gchar	     *dest,
Packit ae235b
					const gchar  *src,
Packit ae235b
					gsize         dest_size);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gsize	              g_strlcat        (gchar	     *dest,
Packit ae235b
					const gchar  *src,
Packit ae235b
					gsize         dest_size);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *               g_strstr_len     (const gchar  *haystack,
Packit ae235b
					gssize        haystack_len,
Packit ae235b
					const gchar  *needle);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *               g_strrstr        (const gchar  *haystack,
Packit ae235b
					const gchar  *needle);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *               g_strrstr_len    (const gchar  *haystack,
Packit ae235b
					gssize        haystack_len,
Packit ae235b
					const gchar  *needle);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean              g_str_has_suffix (const gchar  *str,
Packit ae235b
					const gchar  *suffix);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean              g_str_has_prefix (const gchar  *str,
Packit ae235b
					const gchar  *prefix);
Packit ae235b
Packit ae235b
/* String to/from double conversion functions */
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gdouble	              g_strtod         (const gchar  *nptr,
Packit ae235b
					gchar	    **endptr);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gdouble	              g_ascii_strtod   (const gchar  *nptr,
Packit ae235b
					gchar	    **endptr);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
guint64		      g_ascii_strtoull (const gchar *nptr,
Packit ae235b
					gchar      **endptr,
Packit ae235b
					guint        base);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint64		      g_ascii_strtoll  (const gchar *nptr,
Packit ae235b
					gchar      **endptr,
Packit ae235b
					guint        base);
Packit ae235b
/* 29 bytes should enough for all possible values that
Packit ae235b
 * g_ascii_dtostr can produce.
Packit ae235b
 * Then add 10 for good measure */
Packit ae235b
#define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *               g_ascii_dtostr   (gchar        *buffer,
Packit ae235b
					gint          buf_len,
Packit ae235b
					gdouble       d);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *               g_ascii_formatd  (gchar        *buffer,
Packit ae235b
					gint          buf_len,
Packit ae235b
					const gchar  *format,
Packit ae235b
					gdouble       d);
Packit ae235b
Packit ae235b
/* removes leading spaces */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strchug        (gchar        *string);
Packit ae235b
/* removes trailing spaces */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strchomp       (gchar        *string);
Packit ae235b
/* removes leading & trailing spaces */
Packit ae235b
#define g_strstrip( string )	g_strchomp (g_strchug (string))
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint                  g_ascii_strcasecmp  (const gchar *s1,
Packit ae235b
					   const gchar *s2);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint                  g_ascii_strncasecmp (const gchar *s1,
Packit ae235b
					   const gchar *s2,
Packit ae235b
					   gsize        n);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_ascii_strdown     (const gchar *str,
Packit ae235b
					   gssize       len) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_ascii_strup       (const gchar *str,
Packit ae235b
					   gssize       len) G_GNUC_MALLOC;
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_40
Packit ae235b
gboolean              g_str_is_ascii      (const gchar *str);
Packit ae235b
Packit ae235b
GLIB_DEPRECATED
Packit ae235b
gint                  g_strcasecmp     (const gchar *s1,
Packit ae235b
                                        const gchar *s2);
Packit ae235b
GLIB_DEPRECATED
Packit ae235b
gint                  g_strncasecmp    (const gchar *s1,
Packit ae235b
                                        const gchar *s2,
Packit ae235b
                                        guint        n);
Packit ae235b
GLIB_DEPRECATED
Packit ae235b
gchar*                g_strdown        (gchar       *string);
Packit ae235b
GLIB_DEPRECATED
Packit ae235b
gchar*                g_strup          (gchar       *string);
Packit ae235b
Packit ae235b
Packit ae235b
/* String utility functions that return a newly allocated string which
Packit ae235b
 * ought to be freed with g_free from the caller at some point.
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strdup	       (const gchar *str) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strdup_printf  (const gchar *format,
Packit ae235b
					...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strdup_vprintf (const gchar *format,
Packit ae235b
					va_list      args) G_GNUC_PRINTF(1, 0) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strndup	       (const gchar *str,
Packit ae235b
					gsize        n) G_GNUC_MALLOC;  
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strnfill       (gsize        length,  
Packit ae235b
					gchar        fill_char) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*	              g_strconcat      (const gchar *string1,
Packit ae235b
					...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strjoin	       (const gchar  *separator,
Packit ae235b
					...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
Packit ae235b
Packit ae235b
/* Make a copy of a string interpreting C string -style escape
Packit ae235b
 * sequences. Inverse of g_strescape. The recognized sequences are \b
Packit ae235b
 * \f \n \r \t \\ \" and the octal format.
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strcompress    (const gchar *source) G_GNUC_MALLOC;
Packit ae235b
Packit ae235b
/* Copy a string escaping nonprintable characters like in C strings.
Packit ae235b
 * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
Packit ae235b
 * to a string containing characters that are not to be escaped.
Packit ae235b
 *
Packit ae235b
 * Deprecated API: gchar* g_strescape (const gchar *source);
Packit ae235b
 * Luckily this function wasn't used much, using NULL as second parameter
Packit ae235b
 * provides mostly identical semantics.
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strescape      (const gchar *source,
Packit ae235b
					const gchar *exceptions) G_GNUC_MALLOC;
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer              g_memdup	       (gconstpointer mem,
Packit ae235b
					guint	       byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
Packit ae235b
Packit ae235b
/* NULL terminated string arrays.
Packit ae235b
 * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
Packit ae235b
 * at delim and return a newly allocated string array.
Packit ae235b
 * g_strjoinv() concatenates all of str_array's strings, sliding in an
Packit ae235b
 * optional separator, the returned string is newly allocated.
Packit ae235b
 * g_strfreev() frees the array itself and all of its strings.
Packit ae235b
 * g_strdupv() copies a NULL-terminated array of strings
Packit ae235b
 * g_strv_length() returns the length of a NULL-terminated array of strings
Packit ae235b
 */
Packit ae235b
typedef gchar** GStrv;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar**	              g_strsplit       (const gchar  *string,
Packit ae235b
					const gchar  *delimiter,
Packit ae235b
					gint          max_tokens) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar **	      g_strsplit_set   (const gchar *string,
Packit ae235b
					const gchar *delimiters,
Packit ae235b
					gint         max_tokens) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_strjoinv       (const gchar  *separator,
Packit ae235b
					gchar       **str_array) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void                  g_strfreev       (gchar       **str_array);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar**               g_strdupv        (gchar       **str_array) G_GNUC_MALLOC;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
guint                 g_strv_length    (gchar       **str_array);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar*                g_stpcpy         (gchar        *dest,
Packit ae235b
                                        const char   *src);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_40
Packit ae235b
gchar *                 g_str_to_ascii                                  (const gchar   *str,
Packit ae235b
                                                                         const gchar   *from_locale);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_40
Packit ae235b
gchar **                g_str_tokenize_and_fold                         (const gchar   *string,
Packit ae235b
                                                                         const gchar   *translit_locale,
Packit ae235b
                                                                         gchar       ***ascii_alternates);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_40
Packit ae235b
gboolean                g_str_match_string                              (const gchar   *search_term,
Packit ae235b
                                                                         const gchar   *potential_hit,
Packit ae235b
                                                                         gboolean       accept_alternates);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_44
Packit ae235b
gboolean              g_strv_contains  (const gchar * const *strv,
Packit ae235b
                                        const gchar         *str);
Packit ae235b
Packit ae235b
/* Convenience ASCII string to number API */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GNumberParserError:
Packit ae235b
 * @G_NUMBER_PARSER_ERROR_INVALID: String was not a valid number.
Packit ae235b
 * @G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS: String was a number, but out of bounds.
Packit ae235b
 *
Packit ae235b
 * Error codes returned by functions converting a string to a number.
Packit ae235b
 *
Packit ae235b
 * Since: 2.54
Packit ae235b
 */
Packit ae235b
typedef enum
Packit ae235b
  {
Packit ae235b
    G_NUMBER_PARSER_ERROR_INVALID,
Packit ae235b
    G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS,
Packit ae235b
  } GNumberParserError;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_NUMBER_PARSER_ERROR:
Packit ae235b
 *
Packit ae235b
 * Domain for errors returned by functions converting a string to a
Packit ae235b
 * number.
Packit ae235b
 *
Packit ae235b
 * Since: 2.54
Packit ae235b
 */
Packit ae235b
#define G_NUMBER_PARSER_ERROR (g_number_parser_error_quark ())
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_54
Packit ae235b
GQuark                g_number_parser_error_quark  (void);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_54
Packit ae235b
gboolean              g_ascii_string_to_signed     (const gchar  *str,
Packit ae235b
                                                    guint         base,
Packit ae235b
                                                    gint64        min,
Packit ae235b
                                                    gint64        max,
Packit ae235b
                                                    gint64       *out_num,
Packit ae235b
                                                    GError      **error);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_2_54
Packit ae235b
gboolean              g_ascii_string_to_unsigned   (const gchar  *str,
Packit ae235b
                                                    guint         base,
Packit ae235b
                                                    guint64       min,
Packit ae235b
                                                    guint64       max,
Packit ae235b
                                                    guint64      *out_num,
Packit ae235b
                                                    GError      **error);
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_STRFUNCS_H__ */