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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
23 #error "Only <glib.h> can be included directly."
29 #include <glib/gerror.h>
30 #include <glib/gstring.h>
36 G_REGEX_ERROR_COMPILE
,
37 G_REGEX_ERROR_OPTIMIZE
,
38 G_REGEX_ERROR_REPLACE
,
40 G_REGEX_ERROR_INTERNAL
,
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
82 #define G_REGEX_ERROR g_regex_error_quark ()
84 GQuark
g_regex_error_quark (void);
86 /* Remember to update G_REGEX_COMPILE_MASK in gregex.c after
87 * adding a new flag. */
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
;
106 /* Remember to update G_REGEX_MATCH_MASK in gregex.c after
107 * adding a new flag. */
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
121 typedef struct _GRegex GRegex
;
122 typedef struct _GMatchInfo GMatchInfo
;
124 typedef gboolean (*GRegexEvalCallback
) (const GMatchInfo
*match_info
,
129 GRegex
*g_regex_new (const gchar
*pattern
,
130 GRegexCompileFlags compile_options
,
131 GRegexMatchFlags match_options
,
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
,
140 gchar
*g_regex_escape_string (const gchar
*string
,
144 gboolean
g_regex_match_simple (const gchar
*pattern
,
146 GRegexCompileFlags compile_options
,
147 GRegexMatchFlags match_options
);
148 gboolean
g_regex_match (const GRegex
*regex
,
150 GRegexMatchFlags match_options
,
151 GMatchInfo
**match_info
);
152 gboolean
g_regex_match_full (const GRegex
*regex
,
156 GRegexMatchFlags match_options
,
157 GMatchInfo
**match_info
,
159 gboolean
g_regex_match_all (const GRegex
*regex
,
161 GRegexMatchFlags match_options
,
162 GMatchInfo
**match_info
);
163 gboolean
g_regex_match_all_full (const GRegex
*regex
,
167 GRegexMatchFlags match_options
,
168 GMatchInfo
**match_info
,
171 /* String splitting. */
172 gchar
**g_regex_split_simple (const gchar
*pattern
,
174 GRegexCompileFlags compile_options
,
175 GRegexMatchFlags match_options
);
176 gchar
**g_regex_split (const GRegex
*regex
,
178 GRegexMatchFlags match_options
);
179 gchar
**g_regex_split_full (const GRegex
*regex
,
183 GRegexMatchFlags match_options
,
187 /* String replacement. */
188 gchar
*g_regex_replace (const GRegex
*regex
,
192 const gchar
*replacement
,
193 GRegexMatchFlags match_options
,
195 gchar
*g_regex_replace_literal (const GRegex
*regex
,
199 const gchar
*replacement
,
200 GRegexMatchFlags match_options
,
202 gchar
*g_regex_replace_eval (const GRegex
*regex
,
206 GRegexMatchFlags match_options
,
207 GRegexEvalCallback eval
,
210 gboolean
g_regex_check_replacement (const gchar
*replacement
,
211 gboolean
*has_references
,
215 GRegex
*g_match_info_get_regex (const GMatchInfo
*match_info
);
216 const gchar
*g_match_info_get_string (const GMatchInfo
*match_info
);
218 void g_match_info_free (GMatchInfo
*match_info
);
219 gboolean
g_match_info_next (GMatchInfo
*match_info
,
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
,
227 gchar
*g_match_info_fetch (const GMatchInfo
*match_info
,
229 gboolean
g_match_info_fetch_pos (const GMatchInfo
*match_info
,
233 gchar
*g_match_info_fetch_named (const GMatchInfo
*match_info
,
235 gboolean
g_match_info_fetch_named_pos (const GMatchInfo
*match_info
,
239 gchar
**g_match_info_fetch_all (const GMatchInfo
*match_info
);
243 #endif /* __G_REGEX_H__ */