Split GRegex into GRegex and GMatchInfo. (#419368, Marco Barisione)
[platform/upstream/glib.git] / glib / gregex.h
1 /* GRegex -- regular expression API wrapper around PCRE.
2  *
3  * Copyright (C) 1999, 2000 Scott Wimer
4  * Copyright (C) 2004, Matthias Clasen <mclasen@redhat.com>
5  * Copyright (C) 2005 - 2007, Marco Barisione <marco@barisione.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #ifndef __G_REGEX_H__
23 #define __G_REGEX_H__
24
25 #include <glib/gerror.h>
26 #include <glib/gstring.h>
27
28 G_BEGIN_DECLS
29
30 typedef enum
31 {
32   G_REGEX_ERROR_COMPILE,
33   G_REGEX_ERROR_OPTIMIZE,
34   G_REGEX_ERROR_REPLACE,
35   G_REGEX_ERROR_MATCH
36 } GRegexError;
37
38 #define G_REGEX_ERROR g_regex_error_quark ()
39
40 GQuark g_regex_error_quark (void);
41
42 /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
43  * adding a new flag. */
44 typedef enum
45 {
46   G_REGEX_CASELESS          = 1 << 0,
47   G_REGEX_MULTILINE         = 1 << 1,
48   G_REGEX_DOTALL            = 1 << 2,
49   G_REGEX_EXTENDED          = 1 << 3,
50   G_REGEX_ANCHORED          = 1 << 4,
51   G_REGEX_DOLLAR_ENDONLY    = 1 << 5,
52   G_REGEX_UNGREEDY          = 1 << 9,
53   G_REGEX_RAW               = 1 << 11,
54   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
55   G_REGEX_OPTIMIZE          = 1 << 13,
56   G_REGEX_DUPNAMES          = 1 << 19,
57   G_REGEX_NEWLINE_CR        = 1 << 20,
58   G_REGEX_NEWLINE_LF        = 1 << 21,
59   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
60 } GRegexCompileFlags;
61
62 /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
63  * adding a new flag. */
64 typedef enum
65 {
66   G_REGEX_MATCH_ANCHORED      = 1 << 4,
67   G_REGEX_MATCH_NOTBOL        = 1 << 7,
68   G_REGEX_MATCH_NOTEOL        = 1 << 8,
69   G_REGEX_MATCH_NOTEMPTY      = 1 << 10,
70   G_REGEX_MATCH_PARTIAL       = 1 << 15,
71   G_REGEX_MATCH_NEWLINE_CR    = 1 << 20,
72   G_REGEX_MATCH_NEWLINE_LF    = 1 << 21,
73   G_REGEX_MATCH_NEWLINE_CRLF  = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
74   G_REGEX_MATCH_NEWLINE_ANY   = 1 << 22
75 } GRegexMatchFlags;
76
77 typedef struct _GRegex          GRegex;
78 typedef struct _GMatchInfo      GMatchInfo;
79
80 typedef gboolean (*GRegexEvalCallback)          (const GRegex *,
81                                                  const GMatchInfo *,
82                                                  const gchar *,
83                                                  GString *,
84                                                  gpointer);
85
86
87 GRegex           *g_regex_new                   (const gchar         *pattern,
88                                                  GRegexCompileFlags   compile_options,
89                                                  GRegexMatchFlags     match_options,
90                                                  GError             **error);
91 void              g_regex_free                  (GRegex              *regex);
92 const gchar      *g_regex_get_pattern           (const GRegex        *regex);
93 gint              g_regex_get_string_number     (const GRegex        *regex, 
94                                                  const gchar         *name);
95 gchar            *g_regex_escape_string         (const gchar         *string,
96                                                  gint                 length);
97
98 /* Matching. */
99 gboolean          g_regex_match_simple          (const gchar         *pattern,
100                                                  const gchar         *string,
101                                                  GRegexCompileFlags   compile_options,
102                                                  GRegexMatchFlags     match_options);
103 gboolean          g_regex_match                 (const GRegex        *regex,
104                                                  const gchar         *string,
105                                                  GRegexMatchFlags     match_options,
106                                                  GMatchInfo         **match_info);
107 gboolean          g_regex_match_full            (const GRegex        *regex,
108                                                  const gchar         *string,
109                                                  gssize               string_len,
110                                                  gint                 start_position,
111                                                  GRegexMatchFlags     match_options,
112                                                  GMatchInfo         **match_info,
113                                                  GError             **error);
114 gboolean          g_regex_match_all             (const GRegex        *regex,
115                                                  const gchar         *string,
116                                                  GRegexMatchFlags     match_options,
117                                                  GMatchInfo         **match_info);
118 gboolean          g_regex_match_all_full        (const GRegex        *regex,
119                                                  const gchar         *string,
120                                                  gssize               string_len,
121                                                  gint                 start_position,
122                                                  GRegexMatchFlags     match_options,
123                                                  GMatchInfo         **match_info,
124                                                  GError             **error);
125
126 /* String splitting. */
127 gchar           **g_regex_split_simple          (const gchar         *pattern,
128                                                  const gchar         *string,
129                                                  GRegexCompileFlags   compile_options,
130                                                  GRegexMatchFlags     match_options);
131 gchar           **g_regex_split                 (const GRegex        *regex,
132                                                  const gchar         *string,
133                                                  GRegexMatchFlags     match_options);
134 gchar           **g_regex_split_full            (const GRegex        *regex,
135                                                  const gchar         *string,
136                                                  gssize               string_len,
137                                                  gint                 start_position,
138                                                  GRegexMatchFlags     match_options,
139                                                  gint                 max_tokens,
140                                                  GError             **error);
141
142 /* String replacement. */
143 gchar            *g_regex_replace               (const GRegex        *regex,
144                                                  const gchar         *string,
145                                                  gssize               string_len,
146                                                  gint                 start_position,
147                                                  const gchar         *replacement,
148                                                  GRegexMatchFlags     match_options,
149                                                  GError             **error);
150 gchar            *g_regex_replace_literal       (const GRegex        *regex,
151                                                  const gchar         *string,
152                                                  gssize               string_len,
153                                                  gint                 start_position,
154                                                  const gchar         *replacement,
155                                                  GRegexMatchFlags     match_options,
156                                                  GError             **error);
157 gchar            *g_regex_replace_eval          (const GRegex        *regex,
158                                                  const gchar         *string,
159                                                  gssize               string_len,
160                                                  gint                 start_position,
161                                                  GRegexMatchFlags     match_options,
162                                                  GRegexEvalCallback   eval,
163                                                  gpointer             user_data,
164                                                  GError             **error);
165
166 /* Match info */
167 void              g_match_info_free             (GMatchInfo          *match_info);
168 gboolean          g_match_info_next             (GMatchInfo          *match_info,
169                                                  GError             **error);
170 gboolean          g_match_info_matches          (const GMatchInfo    *match_info);
171 gint              g_match_info_get_match_count  (const GMatchInfo    *match_info);
172 gboolean          g_match_info_is_partial_match (const GMatchInfo    *match_info);
173 gchar            *g_match_info_expand_references(const GMatchInfo    *match_info,
174                                                  const gchar         *string_to_expand,
175                                                  GError             **error);
176 gchar            *g_match_info_fetch            (const GMatchInfo    *match_info,
177                                                  gint                 match_num);
178 gboolean          g_match_info_fetch_pos        (const GMatchInfo    *match_info,
179                                                  gint                 match_num,
180                                                  gint                *start_pos,
181                                                  gint                *end_pos);
182 gchar            *g_match_info_fetch_named      (const GMatchInfo    *match_info,
183                                                  const gchar         *name);
184 gboolean          g_match_info_fetch_named_pos  (const GMatchInfo    *match_info,
185                                                  const gchar         *name,
186                                                  gint                *start_pos,
187                                                  gint                *end_pos);
188 gchar           **g_match_info_fetch_all        (const GMatchInfo    *match_info);
189
190 G_END_DECLS
191
192
193 #endif  /*  __G_REGEX_H__ */