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-Glob-style-pattern-matching.html
27  * outPack = glib
28  * outFile = Pattern
29  * strct   = GPatternSpec
30  * realStrct=
31  * ctorStrct=
32  * clss    = Pattern
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_pattern_spec_
41  * 	- g_pattern_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * structWrap:
49  * 	- GPatternSpec* -> Pattern
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.Pattern;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 
63 private import glib.Str;
64 
65 
66 
67 
68 /**
69  * Description
70  * The g_pattern_match* functions match a string
71  * against a pattern containing '*' and '?' wildcards with similar
72  * semantics as the standard glob() function: '*' matches an arbitrary,
73  * possibly empty, string, '?' matches an arbitrary character.
74  * Note that in contrast to glob(), the '/' character
75  * can be matched by the wildcards, there are no
76  * '[...]' character ranges and '*' and '?' can
77  * not be escaped to include them literally in a
78  * pattern.
79  * When multiple strings must be matched against the same pattern, it
80  * is better to compile the pattern to a GPatternSpec using
81  * g_pattern_spec_new() and use g_pattern_match_string() instead of
82  * g_pattern_match_simple(). This avoids the overhead of repeated
83  * pattern compilation.
84  */
85 public class Pattern
86 {
87 	
88 	/** the main Gtk struct */
89 	protected GPatternSpec* gPatternSpec;
90 	
91 	
92 	public GPatternSpec* getPatternStruct()
93 	{
94 		return gPatternSpec;
95 	}
96 	
97 	
98 	/** the main Gtk struct as a void* */
99 	protected void* getStruct()
100 	{
101 		return cast(void*)gPatternSpec;
102 	}
103 	
104 	/**
105 	 * Sets our main struct and passes it to the parent class
106 	 */
107 	public this (GPatternSpec* gPatternSpec)
108 	{
109 		this.gPatternSpec = gPatternSpec;
110 	}
111 	
112 	/**
113 	 */
114 	
115 	/**
116 	 * Compiles a pattern to a GPatternSpec.
117 	 * Params:
118 	 * pattern = a zero-terminated UTF-8 encoded string
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this (string pattern)
122 	{
123 		// GPatternSpec * g_pattern_spec_new (const gchar *pattern);
124 		auto p = g_pattern_spec_new(Str.toStringz(pattern));
125 		if(p is null)
126 		{
127 			throw new ConstructionException("null returned by g_pattern_spec_new(Str.toStringz(pattern))");
128 		}
129 		this(cast(GPatternSpec*) p);
130 	}
131 	
132 	/**
133 	 * Frees the memory allocated for the GPatternSpec.
134 	 */
135 	public void free()
136 	{
137 		// void g_pattern_spec_free (GPatternSpec *pspec);
138 		g_pattern_spec_free(gPatternSpec);
139 	}
140 	
141 	/**
142 	 * Compares two compiled pattern specs and returns whether they will
143 	 * match the same set of strings.
144 	 * Params:
145 	 * pspec2 = another GPatternSpec
146 	 * Returns: Whether the compiled patterns are equal
147 	 */
148 	public int equal(Pattern pspec2)
149 	{
150 		// gboolean g_pattern_spec_equal (GPatternSpec *pspec1,  GPatternSpec *pspec2);
151 		return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct());
152 	}
153 	
154 	/**
155 	 * Matches a string against a compiled pattern. Passing the correct
156 	 * length of the string given is mandatory. The reversed string can be
157 	 * omitted by passing NULL, this is more efficient if the reversed
158 	 * version of the string to be matched is not at hand, as
159 	 * g_pattern_match() will only construct it if the compiled pattern
160 	 * requires reverse matches.
161 	 * Note that, if the user code will (possibly) match a string against a
162 	 * multitude of patterns containing wildcards, chances are high that
163 	 * some patterns will require a reversed string. In this case, it's
164 	 * more efficient to provide the reversed string to avoid multiple
165 	 * constructions thereof in the various calls to g_pattern_match().
166 	 * Note also that the reverse of a UTF-8 encoded string can in general
167 	 * not be obtained by g_strreverse(). This works
168 	 * only if the string doesn't contain any multibyte characters. GLib
169 	 * offers the g_utf8_strreverse() function to reverse UTF-8 encoded
170 	 * strings.
171 	 * Params:
172 	 * stringLength = the length of string (in bytes, i.e. strlen(),
173 	 * not g_utf8_strlen())
174 	 * string = the UTF-8 encoded string to match
175 	 * stringReversed = the reverse of string or NULL
176 	 * Returns: TRUE if string matches pspec
177 	 */
178 	public int match(uint stringLength, string string, string stringReversed)
179 	{
180 		// gboolean g_pattern_match (GPatternSpec *pspec,  guint string_length,  const gchar *string,  const gchar *string_reversed);
181 		return g_pattern_match(gPatternSpec, stringLength, Str.toStringz(string), Str.toStringz(stringReversed));
182 	}
183 	
184 	/**
185 	 * Matches a string against a compiled pattern. If the string is to be
186 	 * matched against more than one pattern, consider using
187 	 * g_pattern_match() instead while supplying the reversed string.
188 	 * Params:
189 	 * string = the UTF-8 encoded string to match
190 	 * Returns: TRUE if string matches pspec
191 	 */
192 	public int matchString(string string)
193 	{
194 		// gboolean g_pattern_match_string (GPatternSpec *pspec,  const gchar *string);
195 		return g_pattern_match_string(gPatternSpec, Str.toStringz(string));
196 	}
197 	
198 	/**
199 	 * Matches a string against a pattern given as a string. If this
200 	 * function is to be called in a loop, it's more efficient to compile
201 	 * the pattern once with g_pattern_spec_new() and call
202 	 * g_pattern_match_string() repeatedly.
203 	 * Params:
204 	 * pattern = the UTF-8 encoded pattern
205 	 * string = the UTF-8 encoded string to match
206 	 * Returns: TRUE if string matches pspec
207 	 */
208 	public static int matchSimple(string pattern, string string)
209 	{
210 		// gboolean g_pattern_match_simple (const gchar *pattern,  const gchar *string);
211 		return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(string));
212 	}
213 }