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.Pattern;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gtkc.glib;
30 public  import gtkc.glibtypes;
31 
32 
33 /**
34  * A GPatternSpec struct is the 'compiled' form of a pattern. This
35  * structure is opaque and its fields cannot be accessed directly.
36  */
37 public class Pattern
38 {
39 	/** the main Gtk struct */
40 	protected GPatternSpec* gPatternSpec;
41 
42 	/** Get the main Gtk struct */
43 	public GPatternSpec* getPatternStruct()
44 	{
45 		return gPatternSpec;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected void* getStruct()
50 	{
51 		return cast(void*)gPatternSpec;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (GPatternSpec* gPatternSpec)
58 	{
59 		this.gPatternSpec = gPatternSpec;
60 	}
61 
62 	/**
63 	 */
64 
65 	/**
66 	 * Compares two compiled pattern specs and returns whether they will
67 	 * match the same set of strings.
68 	 *
69 	 * Params:
70 	 *     pspec2 = another #GPatternSpec
71 	 *
72 	 * Return: Whether the compiled patterns are equal
73 	 */
74 	public bool equal(Pattern pspec2)
75 	{
76 		return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct()) != 0;
77 	}
78 
79 	/**
80 	 * Frees the memory allocated for the #GPatternSpec.
81 	 */
82 	public void free()
83 	{
84 		g_pattern_spec_free(gPatternSpec);
85 	}
86 
87 	/**
88 	 * Compiles a pattern to a #GPatternSpec.
89 	 *
90 	 * Params:
91 	 *     pattern = a zero-terminated UTF-8 encoded string
92 	 *
93 	 * Return: a newly-allocated #GPatternSpec
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(string pattern)
98 	{
99 		auto p = g_pattern_spec_new(Str.toStringz(pattern));
100 		
101 		if(p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 		
106 		this(cast(GPatternSpec*) p);
107 	}
108 
109 	/**
110 	 * Matches a string against a compiled pattern. Passing the correct
111 	 * length of the string given is mandatory. The reversed string can be
112 	 * omitted by passing %NULL, this is more efficient if the reversed
113 	 * version of the string to be matched is not at hand, as
114 	 * g_pattern_match() will only construct it if the compiled pattern
115 	 * requires reverse matches.
116 	 *
117 	 * Note that, if the user code will (possibly) match a string against a
118 	 * multitude of patterns containing wildcards, chances are high that
119 	 * some patterns will require a reversed string. In this case, it's
120 	 * more efficient to provide the reversed string to avoid multiple
121 	 * constructions thereof in the various calls to g_pattern_match().
122 	 *
123 	 * Note also that the reverse of a UTF-8 encoded string can in general
124 	 * not be obtained by g_strreverse(). This works only if the string
125 	 * does not contain any multibyte characters. GLib offers the
126 	 * g_utf8_strreverse() function to reverse UTF-8 encoded strings.
127 	 *
128 	 * Params:
129 	 *     pspec = a #GPatternSpec
130 	 *     stringLength = the length of @string (in bytes, i.e. strlen(),
131 	 *         not g_utf8_strlen())
132 	 *     str = the UTF-8 encoded string to match
133 	 *     stringReversed = the reverse of @string or %NULL
134 	 *
135 	 * Return: %TRUE if @string matches @pspec
136 	 */
137 	public static bool patternMatch(Pattern pspec, uint stringLength, string str, string stringReversed)
138 	{
139 		return g_pattern_match((pspec is null) ? null : pspec.getPatternStruct(), stringLength, Str.toStringz(str), Str.toStringz(stringReversed)) != 0;
140 	}
141 
142 	/**
143 	 * Matches a string against a pattern given as a string. If this
144 	 * function is to be called in a loop, it's more efficient to compile
145 	 * the pattern once with g_pattern_spec_new() and call
146 	 * g_pattern_match_string() repeatedly.
147 	 *
148 	 * Params:
149 	 *     pattern = the UTF-8 encoded pattern
150 	 *     str = the UTF-8 encoded string to match
151 	 *
152 	 * Return: %TRUE if @string matches @pspec
153 	 */
154 	public static bool patternMatchSimple(string pattern, string str)
155 	{
156 		return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(str)) != 0;
157 	}
158 
159 	/**
160 	 * Matches a string against a compiled pattern. If the string is to be
161 	 * matched against more than one pattern, consider using
162 	 * g_pattern_match() instead while supplying the reversed string.
163 	 *
164 	 * Params:
165 	 *     pspec = a #GPatternSpec
166 	 *     str = the UTF-8 encoded string to match
167 	 *
168 	 * Return: %TRUE if @string matches @pspec
169 	 */
170 	public static bool patternMatchString(Pattern pspec, string str)
171 	{
172 		return g_pattern_match_string((pspec is null) ? null : pspec.getPatternStruct(), Str.toStringz(str)) != 0;
173 	}
174 }