1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module glib.gregex;
7 
8 import glib.gtypes;
9 import glib.gerror;
10 import glib.gstring;
11 
12 
13 enum GRegexError
14 {
15   G_REGEX_ERROR_COMPILE,
16   G_REGEX_ERROR_OPTIMIZE,
17   G_REGEX_ERROR_REPLACE,
18   G_REGEX_ERROR_MATCH,
19   G_REGEX_ERROR_INTERNAL,
20 
21   /* These are the error codes from PCRE + 100 */
22   G_REGEX_ERROR_STRAY_BACKSLASH = 101,
23   G_REGEX_ERROR_MISSING_CONTROL_CHAR = 102,
24   G_REGEX_ERROR_UNRECOGNIZED_ESCAPE = 103,
25   G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER = 104,
26   G_REGEX_ERROR_QUANTIFIER_TOO_BIG = 105,
27   G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS = 106,
28   G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS = 107,
29   G_REGEX_ERROR_RANGE_OUT_OF_ORDER = 108,
30   G_REGEX_ERROR_NOTHING_TO_REPEAT = 109,
31   G_REGEX_ERROR_UNRECOGNIZED_CHARACTER = 112,
32   G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS = 113,
33   G_REGEX_ERROR_UNMATCHED_PARENTHESIS = 114,
34   G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE = 115,
35   G_REGEX_ERROR_UNTERMINATED_COMMENT = 118,
36   G_REGEX_ERROR_EXPRESSION_TOO_LARGE = 120,
37   G_REGEX_ERROR_MEMORY_ERROR = 121,
38   G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND = 125,
39   G_REGEX_ERROR_MALFORMED_CONDITION = 126,
40   G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES = 127,
41   G_REGEX_ERROR_ASSERTION_EXPECTED = 128,
42   G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME = 130,
43   G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED = 131,
44   G_REGEX_ERROR_HEX_CODE_TOO_LARGE = 134,
45   G_REGEX_ERROR_INVALID_CONDITION = 135,
46   G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND = 136,
47   G_REGEX_ERROR_INFINITE_LOOP = 140,
48   G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR = 142,
49   G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME = 143,
50   G_REGEX_ERROR_MALFORMED_PROPERTY = 146,
51   G_REGEX_ERROR_UNKNOWN_PROPERTY = 147,
52   G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG = 148,
53   G_REGEX_ERROR_TOO_MANY_SUBPATTERNS = 149,
54   G_REGEX_ERROR_INVALID_OCTAL_VALUE = 151,
55   G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE = 154,
56   G_REGEX_ERROR_DEFINE_REPETION = 155,
57   G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS = 156,
58   G_REGEX_ERROR_MISSING_BACK_REFERENCE = 157,
59   G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE = 158,
60   G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN = 159,
61   G_REGEX_ERROR_UNKNOWN_BACKTRACKING_CONTROL_VERB  = 160,
62   G_REGEX_ERROR_NUMBER_TOO_BIG = 161,
63   G_REGEX_ERROR_MISSING_SUBPATTERN_NAME = 162,
64   G_REGEX_ERROR_MISSING_DIGIT = 163,
65   G_REGEX_ERROR_INVALID_DATA_CHARACTER = 164,
66   G_REGEX_ERROR_EXTRA_SUBPATTERN_NAME = 165,
67   G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED = 166,
68   G_REGEX_ERROR_INVALID_CONTROL_CHAR = 168,
69   G_REGEX_ERROR_MISSING_NAME = 169,
70   G_REGEX_ERROR_NOT_SUPPORTED_IN_CLASS = 171,
71   G_REGEX_ERROR_TOO_MANY_FORWARD_REFERENCES = 172,
72   G_REGEX_ERROR_NAME_TOO_LONG = 175,
73   G_REGEX_ERROR_CHARACTER_VALUE_TOO_LARGE = 176
74 }
75 
76 //enum G_REGEX_ERROR = g_regex_error_quark ();
77 
78 extern(C)
79 GQuark g_regex_error_quark ();
80 
81 enum GRegexCompileFlags
82 {
83   G_REGEX_CASELESS          = 1 << 0,
84   G_REGEX_MULTILINE         = 1 << 1,
85   G_REGEX_DOTALL            = 1 << 2,
86   G_REGEX_EXTENDED          = 1 << 3,
87   G_REGEX_ANCHORED          = 1 << 4,
88   G_REGEX_DOLLAR_ENDONLY    = 1 << 5,
89   G_REGEX_UNGREEDY          = 1 << 9,
90   G_REGEX_RAW               = 1 << 11,
91   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
92   G_REGEX_OPTIMIZE          = 1 << 13,
93   G_REGEX_FIRSTLINE         = 1 << 18,
94   G_REGEX_DUPNAMES          = 1 << 19,
95   G_REGEX_NEWLINE_CR        = 1 << 20,
96   G_REGEX_NEWLINE_LF        = 1 << 21,
97   G_REGEX_NEWLINE_CRLF      = G_REGEX_NEWLINE_CR | G_REGEX_NEWLINE_LF,
98   G_REGEX_NEWLINE_ANYCRLF   = G_REGEX_NEWLINE_CR | 1 << 22,
99   G_REGEX_BSR_ANYCRLF       = 1 << 23,
100   G_REGEX_JAVASCRIPT_COMPAT = 1 << 25
101 }
102 
103 enum GRegexMatchFlags
104 {
105   G_REGEX_MATCH_ANCHORED         = 1 << 4,
106   G_REGEX_MATCH_NOTBOL           = 1 << 7,
107   G_REGEX_MATCH_NOTEOL           = 1 << 8,
108   G_REGEX_MATCH_NOTEMPTY         = 1 << 10,
109   G_REGEX_MATCH_PARTIAL          = 1 << 15,
110   G_REGEX_MATCH_NEWLINE_CR       = 1 << 20,
111   G_REGEX_MATCH_NEWLINE_LF       = 1 << 21,
112   G_REGEX_MATCH_NEWLINE_CRLF     = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_LF,
113   G_REGEX_MATCH_NEWLINE_ANY      = 1 << 22,
114   G_REGEX_MATCH_NEWLINE_ANYCRLF  = G_REGEX_MATCH_NEWLINE_CR | G_REGEX_MATCH_NEWLINE_ANY,
115   G_REGEX_MATCH_BSR_ANYCRLF      = 1 << 23,
116   G_REGEX_MATCH_BSR_ANY          = 1 << 24,
117   G_REGEX_MATCH_PARTIAL_SOFT     = G_REGEX_MATCH_PARTIAL,
118   G_REGEX_MATCH_PARTIAL_HARD     = 1 << 27,
119   G_REGEX_MATCH_NOTEMPTY_ATSTART = 1 << 28
120 }
121 
122 
123 struct GRegex;
124 
125 
126 struct GMatchInfo;
127 
128 
129 extern (C) {
130 
131     alias GRegexEvalCallback = gboolean function (const(GMatchInfo) *match_info,
132 						 GString          *result,
133 						 gpointer          user_data);
134 
135 
136 
137     GRegex		 *g_regex_new			(const(gchar)         *pattern,
138                              GRegexCompileFlags   compile_options,
139                              GRegexMatchFlags     match_options,
140                              GError             **error);
141 
142     GRegex           *g_regex_ref			(GRegex              *regex);
143 
144     void		  g_regex_unref			(GRegex              *regex);
145 
146     const(gchar)	 *g_regex_get_pattern		(const(GRegex)        *regex);
147 
148     gint		  g_regex_get_max_backref	(const(GRegex)        *regex);
149 
150     gint		  g_regex_get_capture_count	(const(GRegex)        *regex);
151 
152     gboolean          g_regex_get_has_cr_or_lf      (const(GRegex)        *regex);
153 
154     gint              g_regex_get_max_lookbehind    (const(GRegex)        *regex);
155 
156     gint		  g_regex_get_string_number	(const(GRegex)        *regex,
157                              const(gchar)         *name);
158 
159     gchar		 *g_regex_escape_string		(const(gchar)         *str,
160                              gint                 length);
161 
162     gchar		 *g_regex_escape_nul		(const(gchar)         *str,
163                              gint                 length);
164 
165 
166     GRegexCompileFlags g_regex_get_compile_flags    (const(GRegex)        *regex);
167 
168     GRegexMatchFlags   g_regex_get_match_flags      (const(GRegex)        *regex);
169 
170     /* Matching. */
171 
172     gboolean	  g_regex_match_simple		(const(gchar)         *pattern,
173                              const(gchar)         *str,
174                              GRegexCompileFlags   compile_options,
175                              GRegexMatchFlags     match_options);
176 
177     gboolean	  g_regex_match			(const(GRegex)        *regex,
178                              const(gchar)         *str,
179                              GRegexMatchFlags     match_options,
180                              GMatchInfo         **match_info);
181 
182     gboolean	  g_regex_match_full		(const(GRegex)        *regex,
183                              const(gchar)         *str,
184                              gssize               string_len,
185                              gint                 start_position,
186                              GRegexMatchFlags     match_options,
187                              GMatchInfo         **match_info,
188                              GError             **error);
189 
190     gboolean	  g_regex_match_all		(const(GRegex)        *regex,
191                              const(gchar)         *str,
192                              GRegexMatchFlags     match_options,
193                              GMatchInfo         **match_info);
194 
195     gboolean	  g_regex_match_all_full	(const(GRegex)        *regex,
196                              const(gchar)         *str,
197                              gssize               string_len,
198                              gint                 start_position,
199                              GRegexMatchFlags     match_options,
200                              GMatchInfo         **match_info,
201                              GError             **error);
202 
203     /* String splitting. */
204 
205     gchar		**g_regex_split_simple		(const(gchar)         *pattern,
206                              const(gchar)         *str,
207                              GRegexCompileFlags   compile_options,
208                              GRegexMatchFlags     match_options);
209 
210     gchar		**g_regex_split			(const(GRegex)        *regex,
211                              const(gchar)         *str,
212                              GRegexMatchFlags     match_options);
213 
214     gchar		**g_regex_split_full		(const(GRegex)        *regex,
215                              const(gchar)         *str,
216                              gssize               string_len,
217                              gint                 start_position,
218                              GRegexMatchFlags     match_options,
219                              gint                 max_tokens,
220                              GError             **error);
221 
222     /* String replacement. */
223 
224     gchar		 *g_regex_replace		(const(GRegex)        *regex,
225                              const(gchar)         *str,
226                              gssize               string_len,
227                              gint                 start_position,
228                              const(gchar)         *replacement,
229                              GRegexMatchFlags     match_options,
230                              GError             **error);
231 
232     gchar		 *g_regex_replace_literal	(const(GRegex)        *regex,
233                              const(gchar)         *str,
234                              gssize               string_len,
235                              gint                 start_position,
236                              const(gchar)         *replacement,
237                              GRegexMatchFlags     match_options,
238                              GError             **error);
239 
240     gchar		 *g_regex_replace_eval		(const(GRegex)        *regex,
241                              const(gchar)         *str,
242                              gssize               string_len,
243                              gint                 start_position,
244                              GRegexMatchFlags     match_options,
245                              GRegexEvalCallback   eval,
246                              gpointer             user_data,
247                              GError             **error);
248 
249     gboolean	  g_regex_check_replacement	(const(gchar)         *replacement,
250                              gboolean            *has_references,
251                              GError             **error);
252 
253     /* Match info */
254 
255     GRegex		 *g_match_info_get_regex	(const(GMatchInfo)    *match_info);
256 
257     const(gchar)      *g_match_info_get_string       (const(GMatchInfo)    *match_info);
258 
259 
260     GMatchInfo       *g_match_info_ref              (GMatchInfo          *match_info);
261 
262     void              g_match_info_unref            (GMatchInfo          *match_info);
263 
264     void		  g_match_info_free		(GMatchInfo          *match_info);
265 
266     gboolean	  g_match_info_next		(GMatchInfo          *match_info,
267                              GError             **error);
268 
269     gboolean	  g_match_info_matches		(const(GMatchInfo)    *match_info);
270 
271     gint		  g_match_info_get_match_count	(const(GMatchInfo)    *match_info);
272 
273     gboolean	  g_match_info_is_partial_match	(const(GMatchInfo)    *match_info);
274 
275     gchar		 *g_match_info_expand_references(const(GMatchInfo)    *match_info,
276                              const(gchar)         *string_to_expand,
277                              GError             **error);
278 
279     gchar		 *g_match_info_fetch		(const(GMatchInfo)    *match_info,
280                              gint                 match_num);
281 
282     gboolean	  g_match_info_fetch_pos	(const(GMatchInfo)    *match_info,
283                              gint                 match_num,
284                              gint                *start_pos,
285                              gint                *end_pos);
286 
287     gchar		 *g_match_info_fetch_named	(const(GMatchInfo)    *match_info,
288                              const(gchar)         *name);
289 
290     gboolean	  g_match_info_fetch_named_pos	(const(GMatchInfo)    *match_info,
291                              const(gchar)         *name,
292                              gint                *start_pos,
293                              gint                *end_pos);
294 
295     gchar		**g_match_info_fetch_all	(const(GMatchInfo)    *match_info);
296 
297 }
298