2007-03-15 14:01:31 +01:00
|
|
|
/* GRegex -- regular expression API wrapper around PCRE.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999, 2000 Scott Wimer
|
|
|
|
* Copyright (C) 2004, Matthias Clasen <mclasen@redhat.com>
|
2007-04-30 18:02:26 +02:00
|
|
|
* Copyright (C) 2005 - 2007, Marco Barisione <marco@barisione.org>
|
2007-03-15 14:01:31 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __G_REGEX_H__
|
|
|
|
#define __G_REGEX_H__
|
|
|
|
|
2007-03-17 10:49:09 +01:00
|
|
|
#include <glib/gerror.h>
|
|
|
|
#include <glib/gstring.h>
|
2007-03-15 14:01:31 +01:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
G_REGEX_ERROR_COMPILE,
|
|
|
|
G_REGEX_ERROR_OPTIMIZE,
|
|
|
|
G_REGEX_ERROR_REPLACE,
|
|
|
|
G_REGEX_ERROR_MATCH
|
|
|
|
} GRegexError;
|
|
|
|
|
|
|
|
#define G_REGEX_ERROR g_regex_error_quark ()
|
|
|
|
|
|
|
|
GQuark g_regex_error_quark (void);
|
|
|
|
|
|
|
|
/* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
|
|
|
|
* adding a new flag. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
G_REGEX_CASELESS = 1 << 0,
|
|
|
|
G_REGEX_MULTILINE = 1 << 1,
|
|
|
|
G_REGEX_DOTALL = 1 << 2,
|
|
|
|
G_REGEX_EXTENDED = 1 << 3,
|
|
|
|
G_REGEX_ANCHORED = 1 << 4,
|
|
|
|
G_REGEX_DOLLAR_ENDONLY = 1 << 5,
|
|
|
|
G_REGEX_UNGREEDY = 1 << 9,
|
|
|
|
G_REGEX_RAW = 1 << 11,
|
|
|
|
G_REGEX_NO_AUTO_CAPTURE = 1 << 12,
|
2007-04-30 18:02:26 +02:00
|
|
|
G_REGEX_OPTIMIZE = 1 << 13,
|
2007-03-15 14:01:31 +01:00
|
|
|
G_REGEX_DUPNAMES = 1 << 19,
|
|
|
|
G_REGEX_NEWLINE_CR = 1 << 20,
|
|
|
|
G_REGEX_NEWLINE_LF = 1 << 21,
|
|
|
|
G_REGEX_NEWLINE_CRLF = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
|
|
|
|
} GRegexCompileFlags;
|
|
|
|
|
|
|
|
/* Remember to update G_REGEX_MATCH_MASK in gregex.c after
|
|
|
|
* adding a new flag. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
G_REGEX_MATCH_ANCHORED = 1 << 4,
|
|
|
|
G_REGEX_MATCH_NOTBOL = 1 << 7,
|
|
|
|
G_REGEX_MATCH_NOTEOL = 1 << 8,
|
|
|
|
G_REGEX_MATCH_NOTEMPTY = 1 << 10,
|
|
|
|
G_REGEX_MATCH_PARTIAL = 1 << 15,
|
|
|
|
G_REGEX_MATCH_NEWLINE_CR = 1 << 20,
|
|
|
|
G_REGEX_MATCH_NEWLINE_LF = 1 << 21,
|
|
|
|
G_REGEX_MATCH_NEWLINE_CRLF = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
|
2007-04-27 19:43:01 +02:00
|
|
|
G_REGEX_MATCH_NEWLINE_ANY = 1 << 22
|
2007-03-15 14:01:31 +01:00
|
|
|
} GRegexMatchFlags;
|
|
|
|
|
2007-04-30 18:02:26 +02:00
|
|
|
typedef struct _GRegex GRegex;
|
|
|
|
typedef struct _GMatchInfo GMatchInfo;
|
2007-03-15 14:01:31 +01:00
|
|
|
|
2007-04-30 18:02:26 +02:00
|
|
|
typedef gboolean (*GRegexEvalCallback) (const GRegex *,
|
|
|
|
const GMatchInfo *,
|
|
|
|
const gchar *,
|
|
|
|
GString *,
|
|
|
|
gpointer);
|
2007-03-15 14:01:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
GRegex *g_regex_new (const gchar *pattern,
|
|
|
|
GRegexCompileFlags compile_options,
|
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
GError **error);
|
|
|
|
void g_regex_free (GRegex *regex);
|
|
|
|
const gchar *g_regex_get_pattern (const GRegex *regex);
|
2007-04-30 18:37:38 +02:00
|
|
|
gint g_regex_get_max_backref (const GRegex *regex);
|
|
|
|
gint g_regex_get_capture_count (const GRegex *regex);
|
2007-04-30 18:02:26 +02:00
|
|
|
gint g_regex_get_string_number (const GRegex *regex,
|
|
|
|
const gchar *name);
|
|
|
|
gchar *g_regex_escape_string (const gchar *string,
|
|
|
|
gint length);
|
|
|
|
|
|
|
|
/* Matching. */
|
2007-03-15 14:01:31 +01:00
|
|
|
gboolean g_regex_match_simple (const gchar *pattern,
|
|
|
|
const gchar *string,
|
|
|
|
GRegexCompileFlags compile_options,
|
|
|
|
GRegexMatchFlags match_options);
|
2007-04-30 18:02:26 +02:00
|
|
|
gboolean g_regex_match (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
GRegexMatchFlags match_options,
|
2007-04-30 18:02:26 +02:00
|
|
|
GMatchInfo **match_info);
|
|
|
|
gboolean g_regex_match_full (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
GRegexMatchFlags match_options,
|
2007-04-30 18:02:26 +02:00
|
|
|
GMatchInfo **match_info,
|
2007-03-15 14:01:31 +01:00
|
|
|
GError **error);
|
2007-04-30 18:02:26 +02:00
|
|
|
gboolean g_regex_match_all (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
2007-04-30 18:02:26 +02:00
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
GMatchInfo **match_info);
|
|
|
|
gboolean g_regex_match_all_full (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
GRegexMatchFlags match_options,
|
2007-04-30 18:02:26 +02:00
|
|
|
GMatchInfo **match_info,
|
2007-03-15 14:01:31 +01:00
|
|
|
GError **error);
|
2007-04-30 18:02:26 +02:00
|
|
|
|
|
|
|
/* String splitting. */
|
2007-03-15 14:01:31 +01:00
|
|
|
gchar **g_regex_split_simple (const gchar *pattern,
|
|
|
|
const gchar *string,
|
|
|
|
GRegexCompileFlags compile_options,
|
|
|
|
GRegexMatchFlags match_options);
|
2007-04-30 18:02:26 +02:00
|
|
|
gchar **g_regex_split (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
GRegexMatchFlags match_options);
|
2007-04-30 18:02:26 +02:00
|
|
|
gchar **g_regex_split_full (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
gint max_tokens,
|
|
|
|
GError **error);
|
2007-04-30 18:02:26 +02:00
|
|
|
|
|
|
|
/* String replacement. */
|
|
|
|
gchar *g_regex_replace (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
const gchar *replacement,
|
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
GError **error);
|
2007-04-30 18:02:26 +02:00
|
|
|
gchar *g_regex_replace_literal (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
const gchar *replacement,
|
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
GError **error);
|
2007-04-30 18:02:26 +02:00
|
|
|
gchar *g_regex_replace_eval (const GRegex *regex,
|
2007-03-15 14:01:31 +01:00
|
|
|
const gchar *string,
|
|
|
|
gssize string_len,
|
|
|
|
gint start_position,
|
|
|
|
GRegexMatchFlags match_options,
|
|
|
|
GRegexEvalCallback eval,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
|
|
|
|
2007-04-30 18:02:26 +02:00
|
|
|
/* Match info */
|
|
|
|
void g_match_info_free (GMatchInfo *match_info);
|
|
|
|
gboolean g_match_info_next (GMatchInfo *match_info,
|
|
|
|
GError **error);
|
|
|
|
gboolean g_match_info_matches (const GMatchInfo *match_info);
|
|
|
|
gint g_match_info_get_match_count (const GMatchInfo *match_info);
|
|
|
|
gboolean g_match_info_is_partial_match (const GMatchInfo *match_info);
|
|
|
|
gchar *g_match_info_expand_references(const GMatchInfo *match_info,
|
|
|
|
const gchar *string_to_expand,
|
|
|
|
GError **error);
|
|
|
|
gchar *g_match_info_fetch (const GMatchInfo *match_info,
|
|
|
|
gint match_num);
|
|
|
|
gboolean g_match_info_fetch_pos (const GMatchInfo *match_info,
|
|
|
|
gint match_num,
|
|
|
|
gint *start_pos,
|
|
|
|
gint *end_pos);
|
|
|
|
gchar *g_match_info_fetch_named (const GMatchInfo *match_info,
|
|
|
|
const gchar *name);
|
|
|
|
gboolean g_match_info_fetch_named_pos (const GMatchInfo *match_info,
|
|
|
|
const gchar *name,
|
|
|
|
gint *start_pos,
|
|
|
|
gint *end_pos);
|
|
|
|
gchar **g_match_info_fetch_all (const GMatchInfo *match_info);
|
2007-03-15 14:01:31 +01:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __G_REGEX_H__ */
|