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 module glib.MatchInfo;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.Regex;
30 private import glib.Str;
31 private import gtkc.glib;
32 public  import gtkc.glibtypes;
33 
34 
35 /**
36  * A GMatchInfo is an opaque struct used to return information about
37  * matches.
38  */
39 public class MatchInfo
40 {
41 	/** the main Gtk struct */
42 	protected GMatchInfo* gMatchInfo;
43 
44 	/** Get the main Gtk struct */
45 	public GMatchInfo* getMatchInfoStruct()
46 	{
47 		return gMatchInfo;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected void* getStruct()
52 	{
53 		return cast(void*)gMatchInfo;
54 	}
55 
56 	/**
57 	 * Sets our main struct and passes it to the parent class.
58 	 */
59 	public this (GMatchInfo* gMatchInfo)
60 	{
61 		this.gMatchInfo = gMatchInfo;
62 	}
63 
64 	/**
65 	 */
66 
67 	/**
68 	 * Returns a new string containing the text in @string_to_expand with
69 	 * references and escape sequences expanded. References refer to the last
70 	 * match done with @string against @regex and have the same syntax used by
71 	 * g_regex_replace().
72 	 *
73 	 * The @string_to_expand must be UTF-8 encoded even if #G_REGEX_RAW was
74 	 * passed to g_regex_new().
75 	 *
76 	 * The backreferences are extracted from the string passed to the match
77 	 * function, so you cannot call this function after freeing the string.
78 	 *
79 	 * @match_info may be %NULL in which case @string_to_expand must not
80 	 * contain references. For instance "foo\n" does not refer to an actual
81 	 * pattern and '\n' merely will be replaced with \n character,
82 	 * while to expand "\0" (whole match) one needs the result of a match.
83 	 * Use g_regex_check_replacement() to find out whether @string_to_expand
84 	 * contains references.
85 	 *
86 	 * Params:
87 	 *     stringToExpand = the string to expand
88 	 *
89 	 * Return: the expanded string, or %NULL if an error occurred
90 	 *
91 	 * Since: 2.14
92 	 *
93 	 * Throws: GException on failure.
94 	 */
95 	public string expandReferences(string stringToExpand)
96 	{
97 		GError* err = null;
98 		
99 		auto p = g_match_info_expand_references(gMatchInfo, Str.toStringz(stringToExpand), &err);
100 		
101 		if (err !is null)
102 		{
103 			throw new GException( new ErrorG(err) );
104 		}
105 		
106 		return Str.toString(p);
107 	}
108 
109 	/**
110 	 * Retrieves the text matching the @match_num'th capturing
111 	 * parentheses. 0 is the full text of the match, 1 is the first paren
112 	 * set, 2 the second, and so on.
113 	 *
114 	 * If @match_num is a valid sub pattern but it didn't match anything
115 	 * (e.g. sub pattern 1, matching "b" against "(a)?b") then an empty
116 	 * string is returned.
117 	 *
118 	 * If the match was obtained using the DFA algorithm, that is using
119 	 * g_regex_match_all() or g_regex_match_all_full(), the retrieved
120 	 * string is not that of a set of parentheses but that of a matched
121 	 * substring. Substrings are matched in reverse order of length, so
122 	 * 0 is the longest match.
123 	 *
124 	 * The string is fetched from the string passed to the match function,
125 	 * so you cannot call this function after freeing the string.
126 	 *
127 	 * Params:
128 	 *     matchNum = number of the sub expression
129 	 *
130 	 * Return: The matched substring, or %NULL if an error
131 	 *     occurred. You have to free the string yourself
132 	 *
133 	 * Since: 2.14
134 	 */
135 	public string fetch(int matchNum)
136 	{
137 		return Str.toString(g_match_info_fetch(gMatchInfo, matchNum));
138 	}
139 
140 	/**
141 	 * Bundles up pointers to each of the matching substrings from a match
142 	 * and stores them in an array of gchar pointers. The first element in
143 	 * the returned array is the match number 0, i.e. the entire matched
144 	 * text.
145 	 *
146 	 * If a sub pattern didn't match anything (e.g. sub pattern 1, matching
147 	 * "b" against "(a)?b") then an empty string is inserted.
148 	 *
149 	 * If the last match was obtained using the DFA algorithm, that is using
150 	 * g_regex_match_all() or g_regex_match_all_full(), the retrieved
151 	 * strings are not that matched by sets of parentheses but that of the
152 	 * matched substring. Substrings are matched in reverse order of length,
153 	 * so the first one is the longest match.
154 	 *
155 	 * The strings are fetched from the string passed to the match function,
156 	 * so you cannot call this function after freeing the string.
157 	 *
158 	 * Return: a %NULL-terminated array of gchar *
159 	 *     pointers.  It must be freed using g_strfreev(). If the previous
160 	 *     match failed %NULL is returned
161 	 *
162 	 * Since: 2.14
163 	 */
164 	public string[] fetchAll()
165 	{
166 		return Str.toStringArray(g_match_info_fetch_all(gMatchInfo));
167 	}
168 
169 	/**
170 	 * Retrieves the text matching the capturing parentheses named @name.
171 	 *
172 	 * If @name is a valid sub pattern name but it didn't match anything
173 	 * (e.g. sub pattern "X", matching "b" against "(?P<X>a)?b")
174 	 * then an empty string is returned.
175 	 *
176 	 * The string is fetched from the string passed to the match function,
177 	 * so you cannot call this function after freeing the string.
178 	 *
179 	 * Params:
180 	 *     name = name of the subexpression
181 	 *
182 	 * Return: The matched substring, or %NULL if an error
183 	 *     occurred. You have to free the string yourself
184 	 *
185 	 * Since: 2.14
186 	 */
187 	public string fetchNamed(string name)
188 	{
189 		return Str.toString(g_match_info_fetch_named(gMatchInfo, Str.toStringz(name)));
190 	}
191 
192 	/**
193 	 * Retrieves the position in bytes of the capturing parentheses named @name.
194 	 *
195 	 * If @name is a valid sub pattern name but it didn't match anything
196 	 * (e.g. sub pattern "X", matching "b" against "(?P<X>a)?b")
197 	 * then @start_pos and @end_pos are set to -1 and %TRUE is returned.
198 	 *
199 	 * Params:
200 	 *     name = name of the subexpression
201 	 *     startPos = pointer to location where to store
202 	 *         the start position, or %NULL
203 	 *     endPos = pointer to location where to store
204 	 *         the end position, or %NULL
205 	 *
206 	 * Return: %TRUE if the position was fetched, %FALSE otherwise.
207 	 *     If the position cannot be fetched, @start_pos and @end_pos
208 	 *     are left unchanged.
209 	 *
210 	 * Since: 2.14
211 	 */
212 	public bool fetchNamedPos(string name, out int startPos, out int endPos)
213 	{
214 		return g_match_info_fetch_named_pos(gMatchInfo, Str.toStringz(name), &startPos, &endPos) != 0;
215 	}
216 
217 	/**
218 	 * Retrieves the position in bytes of the @match_num'th capturing
219 	 * parentheses. 0 is the full text of the match, 1 is the first
220 	 * paren set, 2 the second, and so on.
221 	 *
222 	 * If @match_num is a valid sub pattern but it didn't match anything
223 	 * (e.g. sub pattern 1, matching "b" against "(a)?b") then @start_pos
224 	 * and @end_pos are set to -1 and %TRUE is returned.
225 	 *
226 	 * If the match was obtained using the DFA algorithm, that is using
227 	 * g_regex_match_all() or g_regex_match_all_full(), the retrieved
228 	 * position is not that of a set of parentheses but that of a matched
229 	 * substring. Substrings are matched in reverse order of length, so
230 	 * 0 is the longest match.
231 	 *
232 	 * Params:
233 	 *     matchNum = number of the sub expression
234 	 *     startPos = pointer to location where to store
235 	 *         the start position, or %NULL
236 	 *     endPos = pointer to location where to store
237 	 *         the end position, or %NULL
238 	 *
239 	 * Return: %TRUE if the position was fetched, %FALSE otherwise. If
240 	 *     the position cannot be fetched, @start_pos and @end_pos are left
241 	 *     unchanged
242 	 *
243 	 * Since: 2.14
244 	 */
245 	public bool fetchPos(int matchNum, out int startPos, out int endPos)
246 	{
247 		return g_match_info_fetch_pos(gMatchInfo, matchNum, &startPos, &endPos) != 0;
248 	}
249 
250 	/**
251 	 * If @match_info is not %NULL, calls g_match_info_unref(); otherwise does
252 	 * nothing.
253 	 *
254 	 * Since: 2.14
255 	 */
256 	public void free()
257 	{
258 		g_match_info_free(gMatchInfo);
259 	}
260 
261 	/**
262 	 * Retrieves the number of matched substrings (including substring 0,
263 	 * that is the whole matched text), so 1 is returned if the pattern
264 	 * has no substrings in it and 0 is returned if the match failed.
265 	 *
266 	 * If the last match was obtained using the DFA algorithm, that is
267 	 * using g_regex_match_all() or g_regex_match_all_full(), the retrieved
268 	 * count is not that of the number of capturing parentheses but that of
269 	 * the number of matched substrings.
270 	 *
271 	 * Return: Number of matched substrings, or -1 if an error occurred
272 	 *
273 	 * Since: 2.14
274 	 */
275 	public int getMatchCount()
276 	{
277 		return g_match_info_get_match_count(gMatchInfo);
278 	}
279 
280 	/**
281 	 * Returns #GRegex object used in @match_info. It belongs to Glib
282 	 * and must not be freed. Use g_regex_ref() if you need to keep it
283 	 * after you free @match_info object.
284 	 *
285 	 * Return: #GRegex object used in @match_info
286 	 *
287 	 * Since: 2.14
288 	 */
289 	public Regex getRegex()
290 	{
291 		auto p = g_match_info_get_regex(gMatchInfo);
292 		
293 		if(p is null)
294 		{
295 			return null;
296 		}
297 		
298 		return new Regex(cast(GRegex*) p);
299 	}
300 
301 	/**
302 	 * Returns the string searched with @match_info. This is the
303 	 * string passed to g_regex_match() or g_regex_replace() so
304 	 * you may not free it before calling this function.
305 	 *
306 	 * Return: the string searched with @match_info
307 	 *
308 	 * Since: 2.14
309 	 */
310 	public string getString()
311 	{
312 		return Str.toString(g_match_info_get_string(gMatchInfo));
313 	}
314 
315 	/**
316 	 * Usually if the string passed to g_regex_match*() matches as far as
317 	 * it goes, but is too short to match the entire pattern, %FALSE is
318 	 * returned. There are circumstances where it might be helpful to
319 	 * distinguish this case from other cases in which there is no match.
320 	 *
321 	 * Consider, for example, an application where a human is required to
322 	 * type in data for a field with specific formatting requirements. An
323 	 * example might be a date in the form ddmmmyy, defined by the pattern
324 	 * "^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$".
325 	 * If the application sees the user’s keystrokes one by one, and can
326 	 * check that what has been typed so far is potentially valid, it is
327 	 * able to raise an error as soon as a mistake is made.
328 	 *
329 	 * GRegex supports the concept of partial matching by means of the
330 	 * #G_REGEX_MATCH_PARTIAL_SOFT and #G_REGEX_MATCH_PARTIAL_HARD flags.
331 	 * When they are used, the return code for
332 	 * g_regex_match() or g_regex_match_full() is, as usual, %TRUE
333 	 * for a complete match, %FALSE otherwise. But, when these functions
334 	 * return %FALSE, you can check if the match was partial calling
335 	 * g_match_info_is_partial_match().
336 	 *
337 	 * The difference between #G_REGEX_MATCH_PARTIAL_SOFT and
338 	 * #G_REGEX_MATCH_PARTIAL_HARD is that when a partial match is encountered
339 	 * with #G_REGEX_MATCH_PARTIAL_SOFT, matching continues to search for a
340 	 * possible complete match, while with #G_REGEX_MATCH_PARTIAL_HARD matching
341 	 * stops at the partial match.
342 	 * When both #G_REGEX_MATCH_PARTIAL_SOFT and #G_REGEX_MATCH_PARTIAL_HARD
343 	 * are set, the latter takes precedence.
344 	 *
345 	 * There were formerly some restrictions on the pattern for partial matching.
346 	 * The restrictions no longer apply.
347 	 *
348 	 * See pcrepartial(3) for more information on partial matching.
349 	 *
350 	 * Return: %TRUE if the match was partial, %FALSE otherwise
351 	 *
352 	 * Since: 2.14
353 	 */
354 	public bool isPartialMatch()
355 	{
356 		return g_match_info_is_partial_match(gMatchInfo) != 0;
357 	}
358 
359 	/**
360 	 * Returns whether the previous match operation succeeded.
361 	 *
362 	 * Return: %TRUE if the previous match operation succeeded,
363 	 *     %FALSE otherwise
364 	 *
365 	 * Since: 2.14
366 	 */
367 	public bool matches()
368 	{
369 		return g_match_info_matches(gMatchInfo) != 0;
370 	}
371 
372 	/**
373 	 * Scans for the next match using the same parameters of the previous
374 	 * call to g_regex_match_full() or g_regex_match() that returned
375 	 * @match_info.
376 	 *
377 	 * The match is done on the string passed to the match function, so you
378 	 * cannot free it before calling this function.
379 	 *
380 	 * Return: %TRUE is the string matched, %FALSE otherwise
381 	 *
382 	 * Since: 2.14
383 	 *
384 	 * Throws: GException on failure.
385 	 */
386 	public bool next()
387 	{
388 		GError* err = null;
389 		
390 		auto p = g_match_info_next(gMatchInfo, &err) != 0;
391 		
392 		if (err !is null)
393 		{
394 			throw new GException( new ErrorG(err) );
395 		}
396 		
397 		return p;
398 	}
399 
400 	/**
401 	 * Increases reference count of @match_info by 1.
402 	 *
403 	 * Return: @match_info
404 	 *
405 	 * Since: 2.30
406 	 */
407 	public MatchInfo doref()
408 	{
409 		auto p = g_match_info_ref(gMatchInfo);
410 		
411 		if(p is null)
412 		{
413 			return null;
414 		}
415 		
416 		return new MatchInfo(cast(GMatchInfo*) p);
417 	}
418 
419 	/**
420 	 * Decreases reference count of @match_info by 1. When reference count drops
421 	 * to zero, it frees all the memory associated with the match_info structure.
422 	 *
423 	 * Since: 2.30
424 	 */
425 	public void unref()
426 	{
427 		g_match_info_unref(gMatchInfo);
428 	}
429 }