1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Perl-compatible-regular-expressions.html
27  * outPack = glib
28  * outFile = Regex
29  * strct   = GRegex
30  * realStrct=
31  * ctorStrct=
32  * clss    = Regex
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_regex_
41  * omit structs:
42  * omit prefixes:
43  * 	- g_match_info_
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- glib.MatchInfo
51  * 	- gtkc.Loader
52  * 	- gtkc.paths
53  * structWrap:
54  * 	- GMatchInfo* -> MatchInfo
55  * 	- GRegex* -> Regex
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module glib.Regex;
62 
63 public  import gtkc.glibtypes;
64 
65 private import gtkc.glib;
66 private import glib.ConstructionException;
67 
68 
69 private import glib.Str;
70 private import glib.ErrorG;
71 private import glib.GException;
72 private import glib.MatchInfo;
73 private import gtkc.Loader;
74 private import gtkc.paths;
75 
76 
77 
78 
79 /**
80  * The g_regex_*() functions implement regular
81  * expression pattern matching using syntax and semantics similar to
82  * Perl regular expression.
83  *
84  * Some functions accept a start_position argument, setting it differs
85  * from just passing over a shortened string and setting G_REGEX_MATCH_NOTBOL
86  * in the case of a pattern that begins with any kind of lookbehind assertion.
87  * For example, consider the pattern "\Biss\B" which finds occurrences of "iss"
88  * in the middle of words. ("\B" matches only if the current position in the
89  * subject is not a word boundary.) When applied to the string "Mississipi"
90  * from the fourth byte, namely "issipi", it does not match, because "\B" is
91  * always false at the start of the subject, which is deemed to be a word
92  * boundary. However, if the entire string is passed , but with
93  * start_position set to 4, it finds the second occurrence of "iss" because
94  * it is able to look behind the starting point to discover that it is
95  * preceded by a letter.
96  *
97  * Note that, unless you set the G_REGEX_RAW flag, all the strings passed
98  * to these functions must be encoded in UTF-8. The lengths and the positions
99  * inside the strings are in bytes and not in characters, so, for instance,
100  * "\xc3\xa0" (i.e. "à") is two bytes long but it is treated as a
101  * single character. If you set G_REGEX_RAW the strings can be non-valid
102  * UTF-8 strings and a byte is treated as a character, so "\xc3\xa0" is two
103  * bytes and two characters long.
104  *
105  * When matching a pattern, "\n" matches only against a "\n" character in
106  * the string, and "\r" matches only a "\r" character. To match any newline
107  * sequence use "\R". This particular group matches either the two-character
108  * sequence CR + LF ("\r\n"), or one of the single characters LF (linefeed,
109  * U+000A, "\n"), VT vertical tab, U+000B, "\v"), FF (formfeed, U+000C, "\f"),
110  * CR (carriage return, U+000D, "\r"), NEL (next line, U+0085), LS (line
111  * separator, U+2028), or PS (paragraph separator, U+2029).
112  *
113  * The behaviour of the dot, circumflex, and dollar metacharacters are
114  * affected by newline characters, the default is to recognize any newline
115  * character (the same characters recognized by "\R"). This can be changed
116  * with G_REGEX_NEWLINE_CR, G_REGEX_NEWLINE_LF and G_REGEX_NEWLINE_CRLF
117  * compile options, and with G_REGEX_MATCH_NEWLINE_ANY,
118  * G_REGEX_MATCH_NEWLINE_CR, G_REGEX_MATCH_NEWLINE_LF and
119  * G_REGEX_MATCH_NEWLINE_CRLF match options. These settings are also
120  * relevant when compiling a pattern if G_REGEX_EXTENDED is set, and an
121  * unescaped "#" outside a character class is encountered. This indicates
122  * a comment that lasts until after the next newline.
123  *
124  * When setting the G_REGEX_JAVASCRIPT_COMPAT flag, pattern syntax and pattern
125  * matching is changed to be compatible with the way that regular expressions
126  * work in JavaScript. More precisely, a lonely ']' character in the pattern
127  * is a syntax error; the '\x' escape only allows 0 to 2 hexadecimal digits, and
128  * you must use the '\u' escape sequence with 4 hex digits to specify a unicode
129  * codepoint instead of '\x' or 'x{....}'. If '\x' or '\u' are not followed by
130  * the specified number of hex digits, they match 'x' and 'u' literally; also
131  * '\U' always matches 'U' instead of being an error in the pattern. Finally,
132  * pattern matching is modified so that back references to an unset subpattern
133  * group produces a match with the empty string instead of an error. See
134  * man:pcreapi(3) for more information.
135  *
136  * Creating and manipulating the same GRegex structure from different
137  * threads is not a problem as GRegex does not modify its internal
138  * state between creation and destruction, on the other hand GMatchInfo
139  * is not threadsafe.
140  *
141  * The regular expressions low-level functionalities are obtained through
142  * the excellent PCRE library
143  * written by Philip Hazel.
144  */
145 public class Regex
146 {
147 	
148 	/** the main Gtk struct */
149 	protected GRegex* gRegex;
150 	
151 	
152 	public GRegex* getRegexStruct()
153 	{
154 		return gRegex;
155 	}
156 	
157 	
158 	/** the main Gtk struct as a void* */
159 	protected void* getStruct()
160 	{
161 		return cast(void*)gRegex;
162 	}
163 	
164 	/**
165 	 * Sets our main struct and passes it to the parent class
166 	 */
167 	public this (GRegex* gRegex)
168 	{
169 		this.gRegex = gRegex;
170 	}
171 	
172 	~this ()
173 	{
174 		if ( Linker.isLoaded(LIBRARY.GLIB) && gRegex !is null )
175 		{
176 			g_regex_unref(gRegex);
177 		}
178 	}
179 	
180 	/**
181 	 */
182 	
183 	/**
184 	 * Compiles the regular expression to an internal form, and does
185 	 * the initial setup of the GRegex structure.
186 	 * Since 2.14
187 	 * Params:
188 	 * pattern = the regular expression
189 	 * compileOptions = compile options for the regular expression, or 0
190 	 * matchOptions = match options for the regular expression, or 0
191 	 * Throws: GException on failure.
192 	 * Throws: ConstructionException GTK+ fails to create the object.
193 	 */
194 	public this (string pattern, GRegexCompileFlags compileOptions, GRegexMatchFlags matchOptions)
195 	{
196 		// GRegex * g_regex_new (const gchar *pattern,  GRegexCompileFlags compile_options,  GRegexMatchFlags match_options,  GError **error);
197 		GError* err = null;
198 		
199 		auto p = g_regex_new(Str.toStringz(pattern), compileOptions, matchOptions, &err);
200 		
201 		if (err !is null)
202 		{
203 			throw new GException( new ErrorG(err) );
204 		}
205 		
206 		if(p is null)
207 		{
208 			throw new ConstructionException("null returned by g_regex_new(Str.toStringz(pattern), compileOptions, matchOptions, &err)");
209 		}
210 		this(cast(GRegex*) p);
211 	}
212 	
213 	/**
214 	 * Increases reference count of regex by 1.
215 	 * Since 2.14
216 	 * Returns: regex
217 	 */
218 	public Regex doref()
219 	{
220 		// GRegex * g_regex_ref (GRegex *regex);
221 		auto p = g_regex_ref(gRegex);
222 		
223 		if(p is null)
224 		{
225 			return null;
226 		}
227 		
228 		return new Regex(cast(GRegex*) p);
229 	}
230 	
231 	/**
232 	 * Decreases reference count of regex by 1. When reference count drops
233 	 * to zero, it frees all the memory associated with the regex structure.
234 	 * Since 2.14
235 	 */
236 	public void unref()
237 	{
238 		// void g_regex_unref (GRegex *regex);
239 		g_regex_unref(gRegex);
240 	}
241 	
242 	/**
243 	 * Gets the pattern string associated with regex, i.e. a copy of
244 	 * the string passed to g_regex_new().
245 	 * Since 2.14
246 	 * Returns: the pattern of regex
247 	 */
248 	public string getPattern()
249 	{
250 		// const gchar * g_regex_get_pattern (const GRegex *regex);
251 		return Str.toString(g_regex_get_pattern(gRegex));
252 	}
253 	
254 	/**
255 	 * Returns the number of the highest back reference
256 	 * in the pattern, or 0 if the pattern does not contain
257 	 * back references.
258 	 * Since 2.14
259 	 * Returns: the number of the highest back reference
260 	 */
261 	public int getMaxBackref()
262 	{
263 		// gint g_regex_get_max_backref (const GRegex *regex);
264 		return g_regex_get_max_backref(gRegex);
265 	}
266 	
267 	/**
268 	 * Returns the number of capturing subpatterns in the pattern.
269 	 * Since 2.14
270 	 * Returns: the number of capturing subpatterns
271 	 */
272 	public int getCaptureCount()
273 	{
274 		// gint g_regex_get_capture_count (const GRegex *regex);
275 		return g_regex_get_capture_count(gRegex);
276 	}
277 	
278 	/**
279 	 * Checks whether the pattern contains explicit CR or LF references.
280 	 * Since 2.34
281 	 * Returns: TRUE if the pattern contains explicit CR or LF references
282 	 */
283 	public int getHasCrOrLf()
284 	{
285 		// gboolean g_regex_get_has_cr_or_lf (const GRegex *regex);
286 		return g_regex_get_has_cr_or_lf(gRegex);
287 	}
288 	
289 	/**
290 	 * Gets the number of characters in the longest lookbehind assertion in the
291 	 * pattern. This information is useful when doing multi-segment matching using
292 	 * the partial matching facilities.
293 	 * Since 2.38
294 	 * Returns: the number of characters in the longest lookbehind assertion.
295 	 */
296 	public int getMaxLookbehind()
297 	{
298 		// gint g_regex_get_max_lookbehind (const GRegex *regex);
299 		return g_regex_get_max_lookbehind(gRegex);
300 	}
301 	
302 	/**
303 	 * Retrieves the number of the subexpression named name.
304 	 * Since 2.14
305 	 * Params:
306 	 * name = name of the subexpression
307 	 * Returns: The number of the subexpression or -1 if name does not exists
308 	 */
309 	public int getStringNumber(string name)
310 	{
311 		// gint g_regex_get_string_number (const GRegex *regex,  const gchar *name);
312 		return g_regex_get_string_number(gRegex, Str.toStringz(name));
313 	}
314 	
315 	/**
316 	 * Returns the compile options that regex was created with.
317 	 * Since 2.26
318 	 * Returns: flags from GRegexCompileFlags
319 	 */
320 	public GRegexCompileFlags getCompileFlags()
321 	{
322 		// GRegexCompileFlags g_regex_get_compile_flags (const GRegex *regex);
323 		return g_regex_get_compile_flags(gRegex);
324 	}
325 	
326 	/**
327 	 * Returns the match options that regex was created with.
328 	 * Since 2.26
329 	 * Returns: flags from GRegexMatchFlags
330 	 */
331 	public GRegexMatchFlags getMatchFlags()
332 	{
333 		// GRegexMatchFlags g_regex_get_match_flags (const GRegex *regex);
334 		return g_regex_get_match_flags(gRegex);
335 	}
336 	
337 	/**
338 	 * Escapes the special characters used for regular expressions
339 	 * in string, for instance "a.b*c" becomes "a\.b\*c". This
340 	 * function is useful to dynamically generate regular expressions.
341 	 * string can contain nul characters that are replaced with "\0",
342 	 * in this case remember to specify the correct length of string
343 	 * in length.
344 	 * Since 2.14
345 	 * Params:
346 	 * string = the string to escape. [array length=length]
347 	 * Returns: a newly-allocated escaped string
348 	 */
349 	public static string escapeString(string string)
350 	{
351 		// gchar * g_regex_escape_string (const gchar *string,  gint length);
352 		return Str.toString(g_regex_escape_string(cast(char*)string.ptr, cast(int) string.length));
353 	}
354 	
355 	/**
356 	 * Escapes the nul characters in string to "\x00". It can be used
357 	 * to compile a regex with embedded nul characters.
358 	 * For completeness, length can be -1 for a nul-terminated string.
359 	 * In this case the output string will be of course equal to string.
360 	 * Since 2.30
361 	 * Params:
362 	 * string = the string to escape
363 	 * Returns: a newly-allocated escaped string
364 	 */
365 	public static string escapeNul(string string)
366 	{
367 		// gchar * g_regex_escape_nul (const gchar *string,  gint length);
368 		return Str.toString(g_regex_escape_nul(cast(char*)string.ptr, cast(int) string.length));
369 	}
370 	
371 	/**
372 	 * Scans for a match in string for pattern.
373 	 * This function is equivalent to g_regex_match() but it does not
374 	 * require to compile the pattern with g_regex_new(), avoiding some
375 	 * lines of code when you need just to do a match without extracting
376 	 * substrings, capture counts, and so on.
377 	 * If this function is to be called on the same pattern more than
378 	 * once, it's more efficient to compile the pattern once with
379 	 * g_regex_new() and then use g_regex_match().
380 	 * Since 2.14
381 	 * Params:
382 	 * pattern = the regular expression
383 	 * string = the string to scan for matches
384 	 * compileOptions = compile options for the regular expression, or 0
385 	 * matchOptions = match options, or 0
386 	 * Returns: TRUE if the string matched, FALSE otherwise
387 	 */
388 	public static int matchSimple(string pattern, string string, GRegexCompileFlags compileOptions, GRegexMatchFlags matchOptions)
389 	{
390 		// gboolean g_regex_match_simple (const gchar *pattern,  const gchar *string,  GRegexCompileFlags compile_options,  GRegexMatchFlags match_options);
391 		return g_regex_match_simple(Str.toStringz(pattern), Str.toStringz(string), compileOptions, matchOptions);
392 	}
393 	
394 	/**
395 	 * Scans for a match in string for the pattern in regex.
396 	 * The match_options are combined with the match options specified
397 	 * when the regex structure was created, letting you have more
398 	 * flexibility in reusing GRegex structures.
399 	 * A GMatchInfo structure, used to get information on the match,
400 	 * is stored in match_info if not NULL. Note that if match_info
401 	 * is not NULL then it is created even if the function returns FALSE,
402 	 * i.e. you must free it regardless if regular expression actually matched.
403 	 * To retrieve all the non-overlapping matches of the pattern in
404 	 * string you can use g_match_info_next().
405 	 * $(DDOC_COMMENT example)
406 	 * string is not copied and is used in GMatchInfo internally. If
407 	 * you use any GMatchInfo method (except g_match_info_free()) after
408 	 * freeing or modifying string then the behaviour is undefined.
409 	 * Since 2.14
410 	 * Params:
411 	 * string = the string to scan for matches
412 	 * matchOptions = match options
413 	 * matchInfo = pointer to location where to store
414 	 * the GMatchInfo, or NULL if you do not need it. [out][allow-none]
415 	 * Returns: TRUE is the string matched, FALSE otherwise
416 	 */
417 	public int match(string string, GRegexMatchFlags matchOptions, out MatchInfo matchInfo)
418 	{
419 		// gboolean g_regex_match (const GRegex *regex,  const gchar *string,  GRegexMatchFlags match_options,  GMatchInfo **match_info);
420 		GMatchInfo* outmatchInfo = null;
421 		
422 		auto p = g_regex_match(gRegex, Str.toStringz(string), matchOptions, &outmatchInfo);
423 		
424 		matchInfo = new MatchInfo(outmatchInfo);
425 		return p;
426 	}
427 	
428 	/**
429 	 * Scans for a match in string for the pattern in regex.
430 	 * The match_options are combined with the match options specified
431 	 * when the regex structure was created, letting you have more
432 	 * flexibility in reusing GRegex structures.
433 	 * Setting start_position differs from just passing over a shortened
434 	 * string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern
435 	 * that begins with any kind of lookbehind assertion, such as "\b".
436 	 * A GMatchInfo structure, used to get information on the match, is
437 	 * stored in match_info if not NULL. Note that if match_info is
438 	 * not NULL then it is created even if the function returns FALSE,
439 	 * i.e. you must free it regardless if regular expression actually
440 	 * matched.
441 	 * string is not copied and is used in GMatchInfo internally. If
442 	 * you use any GMatchInfo method (except g_match_info_free()) after
443 	 * freeing or modifying string then the behaviour is undefined.
444 	 * To retrieve all the non-overlapping matches of the pattern in
445 	 * string you can use g_match_info_next().
446 	 * $(DDOC_COMMENT example)
447 	 * Since 2.14
448 	 * Params:
449 	 * string = the string to scan for matches. [array length=string_len]
450 	 * startPosition = starting index of the string to match
451 	 * matchOptions = match options
452 	 * matchInfo = pointer to location where to store
453 	 * the GMatchInfo, or NULL if you do not need it. [out][allow-none]
454 	 * Returns: TRUE is the string matched, FALSE otherwise
455 	 * Throws: GException on failure.
456 	 */
457 	public int matchFull(string string, int startPosition, GRegexMatchFlags matchOptions, out MatchInfo matchInfo)
458 	{
459 		// gboolean g_regex_match_full (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  GRegexMatchFlags match_options,  GMatchInfo **match_info,  GError **error);
460 		GMatchInfo* outmatchInfo = null;
461 		GError* err = null;
462 		
463 		auto p = g_regex_match_full(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, matchOptions, &outmatchInfo, &err);
464 		
465 		if (err !is null)
466 		{
467 			throw new GException( new ErrorG(err) );
468 		}
469 		
470 		matchInfo = new MatchInfo(outmatchInfo);
471 		return p;
472 	}
473 	
474 	/**
475 	 * Using the standard algorithm for regular expression matching only
476 	 * the longest match in the string is retrieved. This function uses
477 	 * a different algorithm so it can retrieve all the possible matches.
478 	 * For more documentation see g_regex_match_all_full().
479 	 * A GMatchInfo structure, used to get information on the match, is
480 	 * stored in match_info if not NULL. Note that if match_info is
481 	 * not NULL then it is created even if the function returns FALSE,
482 	 * i.e. you must free it regardless if regular expression actually
483 	 * matched.
484 	 * string is not copied and is used in GMatchInfo internally. If
485 	 * you use any GMatchInfo method (except g_match_info_free()) after
486 	 * freeing or modifying string then the behaviour is undefined.
487 	 * Since 2.14
488 	 * Params:
489 	 * string = the string to scan for matches
490 	 * matchOptions = match options
491 	 * matchInfo = pointer to location where to store
492 	 * the GMatchInfo, or NULL if you do not need it. [out][allow-none]
493 	 * Returns: TRUE is the string matched, FALSE otherwise
494 	 */
495 	public int matchAll(string string, GRegexMatchFlags matchOptions, out MatchInfo matchInfo)
496 	{
497 		// gboolean g_regex_match_all (const GRegex *regex,  const gchar *string,  GRegexMatchFlags match_options,  GMatchInfo **match_info);
498 		GMatchInfo* outmatchInfo = null;
499 		
500 		auto p = g_regex_match_all(gRegex, Str.toStringz(string), matchOptions, &outmatchInfo);
501 		
502 		matchInfo = new MatchInfo(outmatchInfo);
503 		return p;
504 	}
505 	
506 	/**
507 	 * Using the standard algorithm for regular expression matching only
508 	 * the longest match in the string is retrieved, it is not possible
509 	 * to obtain all the available matches. For instance matching
510 	 * "<a> <b> <c>" against the pattern "<.*>"
511 	 * you get "<a> <b> <c>".
512 	 * This function uses a different algorithm (called DFA, i.e. deterministic
513 	 * finite automaton), so it can retrieve all the possible matches, all
514 	 * starting at the same point in the string. For instance matching
515 	 * "<a> <b> <c>" against the pattern "<.*>"
516 	 * you would obtain three matches: "<a> <b> <c>",
517 	 * "<a> <b>" and "<a>".
518 	 * The number of matched strings is retrieved using
519 	 * g_match_info_get_match_count(). To obtain the matched strings and
520 	 * their position you can use, respectively, g_match_info_fetch() and
521 	 * g_match_info_fetch_pos(). Note that the strings are returned in
522 	 * reverse order of length; that is, the longest matching string is
523 	 * given first.
524 	 * Note that the DFA algorithm is slower than the standard one and it
525 	 * is not able to capture substrings, so backreferences do not work.
526 	 * Setting start_position differs from just passing over a shortened
527 	 * string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern
528 	 * that begins with any kind of lookbehind assertion, such as "\b".
529 	 * A GMatchInfo structure, used to get information on the match, is
530 	 * stored in match_info if not NULL. Note that if match_info is
531 	 * not NULL then it is created even if the function returns FALSE,
532 	 * i.e. you must free it regardless if regular expression actually
533 	 * matched.
534 	 * string is not copied and is used in GMatchInfo internally. If
535 	 * you use any GMatchInfo method (except g_match_info_free()) after
536 	 * freeing or modifying string then the behaviour is undefined.
537 	 * Since 2.14
538 	 * Params:
539 	 * string = the string to scan for matches. [array length=string_len]
540 	 * startPosition = starting index of the string to match
541 	 * matchOptions = match options
542 	 * matchInfo = pointer to location where to store
543 	 * the GMatchInfo, or NULL if you do not need it. [out][allow-none]
544 	 * Returns: TRUE is the string matched, FALSE otherwise
545 	 * Throws: GException on failure.
546 	 */
547 	public int matchAllFull(string string, int startPosition, GRegexMatchFlags matchOptions, out MatchInfo matchInfo)
548 	{
549 		// gboolean g_regex_match_all_full (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  GRegexMatchFlags match_options,  GMatchInfo **match_info,  GError **error);
550 		GMatchInfo* outmatchInfo = null;
551 		GError* err = null;
552 		
553 		auto p = g_regex_match_all_full(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, matchOptions, &outmatchInfo, &err);
554 		
555 		if (err !is null)
556 		{
557 			throw new GException( new ErrorG(err) );
558 		}
559 		
560 		matchInfo = new MatchInfo(outmatchInfo);
561 		return p;
562 	}
563 	
564 	/**
565 	 * Breaks the string on the pattern, and returns an array of
566 	 * the tokens. If the pattern contains capturing parentheses,
567 	 * then the text for each of the substrings will also be returned.
568 	 * If the pattern does not match anywhere in the string, then the
569 	 * whole string is returned as the first token.
570 	 * This function is equivalent to g_regex_split() but it does
571 	 * not require to compile the pattern with g_regex_new(), avoiding
572 	 * some lines of code when you need just to do a split without
573 	 * extracting substrings, capture counts, and so on.
574 	 * If this function is to be called on the same pattern more than
575 	 * once, it's more efficient to compile the pattern once with
576 	 * g_regex_new() and then use g_regex_split().
577 	 * As a special case, the result of splitting the empty string ""
578 	 * is an empty vector, not a vector containing a single string.
579 	 * The reason for this special case is that being able to represent
580 	 * a empty vector is typically more useful than consistent handling
581 	 * of empty elements. If you do need to represent empty elements,
582 	 * you'll need to check for the empty string before calling this
583 	 * function.
584 	 * A pattern that can match empty strings splits string into
585 	 * separate characters wherever it matches the empty string between
586 	 * characters. For example splitting "ab c" using as a separator
587 	 * "\s*", you will get "a", "b" and "c".
588 	 * Since 2.14
589 	 * Params:
590 	 * pattern = the regular expression
591 	 * string = the string to scan for matches
592 	 * compileOptions = compile options for the regular expression, or 0
593 	 * matchOptions = match options, or 0
594 	 * Returns: a NULL-terminated array of strings. Free it using g_strfreev(). [transfer full]
595 	 */
596 	public static string[] splitSimple(string pattern, string string, GRegexCompileFlags compileOptions, GRegexMatchFlags matchOptions)
597 	{
598 		// gchar ** g_regex_split_simple (const gchar *pattern,  const gchar *string,  GRegexCompileFlags compile_options,  GRegexMatchFlags match_options);
599 		return Str.toStringArray(g_regex_split_simple(Str.toStringz(pattern), Str.toStringz(string), compileOptions, matchOptions));
600 	}
601 	
602 	/**
603 	 * Breaks the string on the pattern, and returns an array of the tokens.
604 	 * If the pattern contains capturing parentheses, then the text for each
605 	 * of the substrings will also be returned. If the pattern does not match
606 	 * anywhere in the string, then the whole string is returned as the first
607 	 * token.
608 	 * As a special case, the result of splitting the empty string "" is an
609 	 * empty vector, not a vector containing a single string. The reason for
610 	 * this special case is that being able to represent a empty vector is
611 	 * typically more useful than consistent handling of empty elements. If
612 	 * you do need to represent empty elements, you'll need to check for the
613 	 * empty string before calling this function.
614 	 * A pattern that can match empty strings splits string into separate
615 	 * characters wherever it matches the empty string between characters.
616 	 * For example splitting "ab c" using as a separator "\s*", you will get
617 	 * "a", "b" and "c".
618 	 * Since 2.14
619 	 * Params:
620 	 * string = the string to split with the pattern
621 	 * matchOptions = match time option flags
622 	 * Returns: a NULL-terminated gchar ** array. Free it using g_strfreev(). [transfer full]
623 	 */
624 	public string[] split(string string, GRegexMatchFlags matchOptions)
625 	{
626 		// gchar ** g_regex_split (const GRegex *regex,  const gchar *string,  GRegexMatchFlags match_options);
627 		return Str.toStringArray(g_regex_split(gRegex, Str.toStringz(string), matchOptions));
628 	}
629 	
630 	/**
631 	 * Breaks the string on the pattern, and returns an array of the tokens.
632 	 * If the pattern contains capturing parentheses, then the text for each
633 	 * of the substrings will also be returned. If the pattern does not match
634 	 * anywhere in the string, then the whole string is returned as the first
635 	 * token.
636 	 * As a special case, the result of splitting the empty string "" is an
637 	 * empty vector, not a vector containing a single string. The reason for
638 	 * this special case is that being able to represent a empty vector is
639 	 * typically more useful than consistent handling of empty elements. If
640 	 * you do need to represent empty elements, you'll need to check for the
641 	 * empty string before calling this function.
642 	 * A pattern that can match empty strings splits string into separate
643 	 * characters wherever it matches the empty string between characters.
644 	 * For example splitting "ab c" using as a separator "\s*", you will get
645 	 * "a", "b" and "c".
646 	 * Setting start_position differs from just passing over a shortened
647 	 * string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern
648 	 * that begins with any kind of lookbehind assertion, such as "\b".
649 	 * Since 2.14
650 	 * Params:
651 	 * string = the string to split with the pattern. [array length=string_len]
652 	 * startPosition = starting index of the string to match
653 	 * matchOptions = match time option flags
654 	 * maxTokens = the maximum number of tokens to split string into.
655 	 * If this is less than 1, the string is split completely
656 	 * Returns: a NULL-terminated gchar ** array. Free it using g_strfreev(). [transfer full]
657 	 * Throws: GException on failure.
658 	 */
659 	public string[] splitFull(string string, int startPosition, GRegexMatchFlags matchOptions, int maxTokens)
660 	{
661 		// gchar ** g_regex_split_full (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  GRegexMatchFlags match_options,  gint max_tokens,  GError **error);
662 		GError* err = null;
663 		
664 		auto p = g_regex_split_full(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, matchOptions, maxTokens, &err);
665 		
666 		if (err !is null)
667 		{
668 			throw new GException( new ErrorG(err) );
669 		}
670 		
671 		return Str.toStringArray(p);
672 	}
673 	
674 	/**
675 	 * Replaces all occurrences of the pattern in regex with the
676 	 * replacement text. Backreferences of the form '\number' or
677 	 * '\g<number>' in the replacement text are interpolated by the
678 	 * number-th captured subexpression of the match, '\g<name>' refers
679 	 * to the captured subexpression with the given name. '\0' refers to the
680 	 * complete match, but '\0' followed by a number is the octal representation
681 	 * of a character. To include a literal '\' in the replacement, write '\\'.
682 	 * Since 2.14
683 	 * Params:
684 	 * string = the string to perform matches against. [array length=string_len]
685 	 * startPosition = starting index of the string to match
686 	 * replacement = text to replace each match with
687 	 * matchOptions = options for the match
688 	 * Returns: a newly allocated string containing the replacements
689 	 * Throws: GException on failure.
690 	 */
691 	public string replace(string string, int startPosition, string replacement, GRegexMatchFlags matchOptions)
692 	{
693 		// gchar * g_regex_replace (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  const gchar *replacement,  GRegexMatchFlags match_options,  GError **error);
694 		GError* err = null;
695 		
696 		auto p = g_regex_replace(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, Str.toStringz(replacement), matchOptions, &err);
697 		
698 		if (err !is null)
699 		{
700 			throw new GException( new ErrorG(err) );
701 		}
702 		
703 		return Str.toString(p);
704 	}
705 	
706 	/**
707 	 * Replaces all occurrences of the pattern in regex with the
708 	 * replacement text. replacement is replaced literally, to
709 	 * include backreferences use g_regex_replace().
710 	 * Setting start_position differs from just passing over a
711 	 * shortened string and setting G_REGEX_MATCH_NOTBOL in the
712 	 * case of a pattern that begins with any kind of lookbehind
713 	 * assertion, such as "\b".
714 	 * Since 2.14
715 	 * Params:
716 	 * string = the string to perform matches against. [array length=string_len]
717 	 * startPosition = starting index of the string to match
718 	 * replacement = text to replace each match with
719 	 * matchOptions = options for the match
720 	 * Returns: a newly allocated string containing the replacements
721 	 * Throws: GException on failure.
722 	 */
723 	public string replaceLiteral(string string, int startPosition, string replacement, GRegexMatchFlags matchOptions)
724 	{
725 		// gchar * g_regex_replace_literal (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  const gchar *replacement,  GRegexMatchFlags match_options,  GError **error);
726 		GError* err = null;
727 		
728 		auto p = g_regex_replace_literal(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, Str.toStringz(replacement), matchOptions, &err);
729 		
730 		if (err !is null)
731 		{
732 			throw new GException( new ErrorG(err) );
733 		}
734 		
735 		return Str.toString(p);
736 	}
737 	
738 	/**
739 	 * Replaces occurrences of the pattern in regex with the output of
740 	 * eval for that occurrence.
741 	 * Setting start_position differs from just passing over a shortened
742 	 * string and setting G_REGEX_MATCH_NOTBOL in the case of a pattern
743 	 * that begins with any kind of lookbehind assertion, such as "\b".
744 	 * The following example uses g_regex_replace_eval() to replace multiple
745 	 * Since 2.14
746 	 * Params:
747 	 * string = string to perform matches against. [array length=string_len]
748 	 * startPosition = starting index of the string to match
749 	 * matchOptions = options for the match
750 	 * eval = a function to call for each match
751 	 * userData = user data to pass to the function
752 	 * Returns: a newly allocated string containing the replacements
753 	 * Throws: GException on failure.
754 	 */
755 	public string replaceEval(string string, int startPosition, GRegexMatchFlags matchOptions, GRegexEvalCallback eval, void* userData)
756 	{
757 		// gchar * g_regex_replace_eval (const GRegex *regex,  const gchar *string,  gssize string_len,  gint start_position,  GRegexMatchFlags match_options,  GRegexEvalCallback eval,  gpointer user_data,  GError **error);
758 		GError* err = null;
759 		
760 		auto p = g_regex_replace_eval(gRegex, cast(char*)string.ptr, cast(int) string.length, startPosition, matchOptions, eval, userData, &err);
761 		
762 		if (err !is null)
763 		{
764 			throw new GException( new ErrorG(err) );
765 		}
766 		
767 		return Str.toString(p);
768 	}
769 	
770 	/**
771 	 * Checks whether replacement is a valid replacement string
772 	 * (see g_regex_replace()), i.e. that all escape sequences in
773 	 * it are valid.
774 	 * If has_references is not NULL then replacement is checked
775 	 * for pattern references. For instance, replacement text 'foo\n'
776 	 * does not contain references and may be evaluated without information
777 	 * about actual match, but '\0\1' (whole match followed by first
778 	 * subpattern) requires valid GMatchInfo object.
779 	 * Since 2.14
780 	 * Params:
781 	 * replacement = the replacement string
782 	 * hasReferences = location to store information about
783 	 * references in replacement or NULL. [out][allow-none]
784 	 * Returns: whether replacement is a valid replacement string
785 	 * Throws: GException on failure.
786 	 */
787 	public static int checkReplacement(string replacement, out int hasReferences)
788 	{
789 		// gboolean g_regex_check_replacement (const gchar *replacement,  gboolean *has_references,  GError **error);
790 		GError* err = null;
791 		
792 		auto p = g_regex_check_replacement(Str.toStringz(replacement), &hasReferences, &err);
793 		
794 		if (err !is null)
795 		{
796 			throw new GException( new ErrorG(err) );
797 		}
798 		
799 		return p;
800 	}
801 }