add missing #include "config.h"
[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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
23 #error "Only <glib.h> can be included directly."
24 #endif
25
26 #ifndef __G_REGEX_H__
27 #define __G_REGEX_H__
28
29 #include <glib/gerror.h>
30 #include <glib/gstring.h>
31
32 G_BEGIN_DECLS
33
34 typedef enum
35 {
36   G_REGEX_ERROR_COMPILE,
37   G_REGEX_ERROR_OPTIMIZE,
38   G_REGEX_ERROR_REPLACE,
39   G_REGEX_ERROR_MATCH,
40   G_REGEX_ERROR_INTERNAL,
41
42   /* These are the error codes from PCRE + 100 */
43   G_REGEX_ERROR_STRAY_BACKSLASH = 101,
44   G_REGEX_ERROR_MISSING_CONTROL_CHAR = 102,
45   G_REGEX_ERROR_UNRECOGNIZED_ESCAPE = 103,
46   G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER = 104,
47   G_REGEX_ERROR_QUANTIFIER_TOO_BIG = 105,
48   G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS = 106,
49   G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS = 107,
50   G_REGEX_ERROR_RANGE_OUT_OF_ORDER = 108,
51   G_REGEX_ERROR_NOTHING_TO_REPEAT = 109,
52   G_REGEX_ERROR_UNRECOGNIZED_CHARACTER = 112,
53   G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS = 113,
54   G_REGEX_ERROR_UNMATCHED_PARENTHESIS = 114,
55   G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE = 115,
56   G_REGEX_ERROR_UNTERMINATED_COMMENT = 118,
57   G_REGEX_ERROR_EXPRESSION_TOO_LARGE = 120,
58   G_REGEX_ERROR_MEMORY_ERROR = 121,
59   G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND = 125,
60   G_REGEX_ERROR_MALFORMED_CONDITION = 126,
61   G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES = 127,
62   G_REGEX_ERROR_ASSERTION_EXPECTED = 128,
63   G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME = 130,
64   G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED = 131,
65   G_REGEX_ERROR_HEX_CODE_TOO_LARGE = 134,
66   G_REGEX_ERROR_INVALID_CONDITION = 135,
67   G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND = 136,
68   G_REGEX_ERROR_INFINITE_LOOP = 140,
69   G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR = 142,
70   G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME = 143,
71   G_REGEX_ERROR_MALFORMED_PROPERTY = 146,
72   G_REGEX_ERROR_UNKNOWN_PROPERTY = 147,
73   G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG = 148,
74   G_REGEX_ERROR_TOO_MANY_SUBPATTERNS = 149,
75   G_REGEX_ERROR_INVALID_OCTAL_VALUE = 151,
76   G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE = 154,
77   G_REGEX_ERROR_DEFINE_REPETION = 155,
78   G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS = 156,
79   G_REGEX_ERROR_MISSING_BACK_REFERENCE = 157
80 } GRegexError;
81
82 #define G_REGEX_ERROR g_regex_error_quark ()
83
84 GQuark g_regex_error_quark (void);
85
86 /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
87  * adding a new flag. */
88 typedef enum
89 {
90   G_REGEX_CASELESS          = 1 << 0,
91   G_REGEX_MULTILINE         = 1 << 1,
92   G_REGEX_DOTALL            = 1 << 2,
93   G_REGEX_EXTENDED          = 1 << 3,
94   G_REGEX_ANCHORED          = 1 << 4,
95   G_REGEX_DOLLAR_ENDONLY    = 1 << 5,
96   G_REGEX_UNGREEDY          = 1 << 9,
97   G_REGEX_RAW               = 1 << 11,
98   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
99   G_REGEX_OPTIMIZE          = 1 << 13,
100   G_REGEX_DUPNAMES          = 1 << 19,
101   G_REGEX_NEWLINE_CR        = 1 << 20,
102   G_REGEX_NEWLINE_LF        = 1 << 21,
103   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF
104 } GRegexCompileFlags;
105
106 /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
107  * adding a new flag. */
108 typedef enum
109 {
110   G_REGEX_MATCH_ANCHORED      = 1 << 4,
111   G_REGEX_MATCH_NOTBOL        = 1 << 7,
112   G_REGEX_MATCH_NOTEOL        = 1 << 8,
113   G_REGEX_MATCH_NOTEMPTY      = 1 << 10,
114   G_REGEX_MATCH_PARTIAL       = 1 << 15,
115   G_REGEX_MATCH_NEWLINE_CR    = 1 << 20,
116   G_REGEX_MATCH_NEWLINE_LF    = 1 << 21,
117   G_REGEX_MATCH_NEWLINE_CRLF  = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
118   G_REGEX_MATCH_NEWLINE_ANY   = 1 << 22
119 } GRegexMatchFlags;
120
121 typedef struct _GRegex          GRegex;
122 typedef struct _GMatchInfo      GMatchInfo;
123
124 typedef gboolean (*GRegexEvalCallback)          (const GMatchInfo *match_info,
125                                                  GString          *result,
126                                                  gpointer          user_data);
127
128
129 GRegex           *g_regex_new                   (const gchar         *pattern,
130                                                  GRegexCompileFlags   compile_options,
131                                                  GRegexMatchFlags     match_options,
132                                                  GError             **error);
133 GRegex           *g_regex_ref                   (GRegex              *regex);
134 void              g_regex_unref                 (GRegex              *regex);
135 const gchar      *g_regex_get_pattern           (const GRegex        *regex);
136 gint              g_regex_get_max_backref       (const GRegex        *regex);
137 gint              g_regex_get_capture_count     (const GRegex        *regex);
138 gint              g_regex_get_string_number     (const GRegex        *regex, 
139                                                  const gchar         *name);
140 gchar            *g_regex_escape_string         (const gchar         *string,
141                                                  gint                 length);
142
143 /* Matching. */
144 gboolean          g_regex_match_simple          (const gchar         *pattern,
145                                                  const gchar         *string,
146                                                  GRegexCompileFlags   compile_options,
147                                                  GRegexMatchFlags     match_options);
148 gboolean          g_regex_match                 (const GRegex        *regex,
149                                                  const gchar         *string,
150                                                  GRegexMatchFlags     match_options,
151                                                  GMatchInfo         **match_info);
152 gboolean          g_regex_match_full            (const GRegex        *regex,
153                                                  const gchar         *string,
154                                                  gssize               string_len,
155                                                  gint                 start_position,
156                                                  GRegexMatchFlags     match_options,
157                                                  GMatchInfo         **match_info,
158                                                  GError             **error);
159 gboolean          g_regex_match_all             (const GRegex        *regex,
160                                                  const gchar         *string,
161                                                  GRegexMatchFlags     match_options,
162                                                  GMatchInfo         **match_info);
163 gboolean          g_regex_match_all_full        (const GRegex        *regex,
164                                                  const gchar         *string,
165                                                  gssize               string_len,
166                                                  gint                 start_position,
167                                                  GRegexMatchFlags     match_options,
168                                                  GMatchInfo         **match_info,
169                                                  GError             **error);
170
171 /* String splitting. */
172 gchar           **g_regex_split_simple          (const gchar         *pattern,
173                                                  const gchar         *string,
174                                                  GRegexCompileFlags   compile_options,
175                                                  GRegexMatchFlags     match_options);
176 gchar           **g_regex_split                 (const GRegex        *regex,
177                                                  const gchar         *string,
178                                                  GRegexMatchFlags     match_options);
179 gchar           **g_regex_split_full            (const GRegex        *regex,
180                                                  const gchar         *string,
181                                                  gssize               string_len,
182                                                  gint                 start_position,
183                                                  GRegexMatchFlags     match_options,
184                                                  gint                 max_tokens,
185                                                  GError             **error);
186
187 /* String replacement. */
188 gchar            *g_regex_replace               (const GRegex        *regex,
189                                                  const gchar         *string,
190                                                  gssize               string_len,
191                                                  gint                 start_position,
192                                                  const gchar         *replacement,
193                                                  GRegexMatchFlags     match_options,
194                                                  GError             **error);
195 gchar            *g_regex_replace_literal       (const GRegex        *regex,
196                                                  const gchar         *string,
197                                                  gssize               string_len,
198                                                  gint                 start_position,
199                                                  const gchar         *replacement,
200                                                  GRegexMatchFlags     match_options,
201                                                  GError             **error);
202 gchar            *g_regex_replace_eval          (const GRegex        *regex,
203                                                  const gchar         *string,
204                                                  gssize               string_len,
205                                                  gint                 start_position,
206                                                  GRegexMatchFlags     match_options,
207                                                  GRegexEvalCallback   eval,
208                                                  gpointer             user_data,
209                                                  GError             **error);
210 gboolean          g_regex_check_replacement     (const gchar         *replacement,
211                                                  gboolean            *has_references,
212                                                  GError             **error);
213
214 /* Match info */
215 GRegex           *g_match_info_get_regex        (const GMatchInfo    *match_info);
216 const gchar      *g_match_info_get_string       (const GMatchInfo    *match_info);
217
218 void              g_match_info_free             (GMatchInfo          *match_info);
219 gboolean          g_match_info_next             (GMatchInfo          *match_info,
220                                                  GError             **error);
221 gboolean          g_match_info_matches          (const GMatchInfo    *match_info);
222 gint              g_match_info_get_match_count  (const GMatchInfo    *match_info);
223 gboolean          g_match_info_is_partial_match (const GMatchInfo    *match_info);
224 gchar            *g_match_info_expand_references(const GMatchInfo    *match_info,
225                                                  const gchar         *string_to_expand,
226                                                  GError             **error);
227 gchar            *g_match_info_fetch            (const GMatchInfo    *match_info,
228                                                  gint                 match_num);
229 gboolean          g_match_info_fetch_pos        (const GMatchInfo    *match_info,
230                                                  gint                 match_num,
231                                                  gint                *start_pos,
232                                                  gint                *end_pos);
233 gchar            *g_match_info_fetch_named      (const GMatchInfo    *match_info,
234                                                  const gchar         *name);
235 gboolean          g_match_info_fetch_named_pos  (const GMatchInfo    *match_info,
236                                                  const gchar         *name,
237                                                  gint                *start_pos,
238                                                  gint                *end_pos);
239 gchar           **g_match_info_fetch_all        (const GMatchInfo    *match_info);
240
241 G_END_DECLS
242
243 #endif  /*  __G_REGEX_H__ */