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