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
25 #include <glib/gerror.h>
26 #include <glib/gstring.h>
32 G_REGEX_ERROR_COMPILE
,
33 G_REGEX_ERROR_OPTIMIZE
,
34 G_REGEX_ERROR_REPLACE
,
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
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. */
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. */
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
117 typedef struct _GRegex GRegex
;
118 typedef struct _GMatchInfo GMatchInfo
;
120 typedef gboolean (*GRegexEvalCallback
) (const GMatchInfo
*match_info
,
125 GRegex
*g_regex_new (const gchar
*pattern
,
126 GRegexCompileFlags compile_options
,
127 GRegexMatchFlags match_options
,
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
,
136 gchar
*g_regex_escape_string (const gchar
*string
,
140 gboolean
g_regex_match_simple (const gchar
*pattern
,
142 GRegexCompileFlags compile_options
,
143 GRegexMatchFlags match_options
);
144 gboolean
g_regex_match (const GRegex
*regex
,
146 GRegexMatchFlags match_options
,
147 GMatchInfo
**match_info
);
148 gboolean
g_regex_match_full (const GRegex
*regex
,
152 GRegexMatchFlags match_options
,
153 GMatchInfo
**match_info
,
155 gboolean
g_regex_match_all (const GRegex
*regex
,
157 GRegexMatchFlags match_options
,
158 GMatchInfo
**match_info
);
159 gboolean
g_regex_match_all_full (const GRegex
*regex
,
163 GRegexMatchFlags match_options
,
164 GMatchInfo
**match_info
,
167 /* String splitting. */
168 gchar
**g_regex_split_simple (const gchar
*pattern
,
170 GRegexCompileFlags compile_options
,
171 GRegexMatchFlags match_options
);
172 gchar
**g_regex_split (const GRegex
*regex
,
174 GRegexMatchFlags match_options
);
175 gchar
**g_regex_split_full (const GRegex
*regex
,
179 GRegexMatchFlags match_options
,
183 /* String replacement. */
184 gchar
*g_regex_replace (const GRegex
*regex
,
188 const gchar
*replacement
,
189 GRegexMatchFlags match_options
,
191 gchar
*g_regex_replace_literal (const GRegex
*regex
,
195 const gchar
*replacement
,
196 GRegexMatchFlags match_options
,
198 gchar
*g_regex_replace_eval (const GRegex
*regex
,
202 GRegexMatchFlags match_options
,
203 GRegexEvalCallback eval
,
206 gboolean
g_regex_check_replacement (const gchar
*replacement
,
207 gboolean
*has_references
,
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
,
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
,
223 gchar
*g_match_info_fetch (const GMatchInfo
*match_info
,
225 gboolean
g_match_info_fetch_pos (const GMatchInfo
*match_info
,
229 gchar
*g_match_info_fetch_named (const GMatchInfo
*match_info
,
231 gboolean
g_match_info_fetch_named_pos (const GMatchInfo
*match_info
,
235 gchar
**g_match_info_fetch_all (const GMatchInfo
*match_info
);
240 #endif /* __G_REGEX_H__ */