alternative to assert
[gtkD.git] / gtkD / src / glib / Pattern.d
blobe0d056e6c11f3f5803b4384578b44d71a9bbbd60
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Glob-style-pattern-matching.html
26 * outPack = glib
27 * outFile = Pattern
28 * strct = GPatternSpec
29 * realStrct=
30 * ctorStrct=
31 * clss = Pattern
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_pattern_spec_
40 * - g_pattern_match_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * structWrap:
47 * - GPatternSpec* -> Pattern
48 * module aliases:
49 * local aliases:
52 module glib.Pattern;
54 version(noAssert)
56 version(Tango)
58 import tango.io.Stdout; // use the tango loging?
62 private import gtkc.glibtypes;
64 private import gtkc.glib;
67 private import glib.Str;
72 /**
73 * Description
74 * The g_pattern_match* functions match a string
75 * against a pattern containing '*' and '?' wildcards with similar semantics
76 * as the standard glob() function: '*' matches an arbitrary, possibly empty,
77 * string, '?' matches an arbitrary character.
78 * Note that in contrast to glob(), the '/' character
79 * can be matched by the wildcards, there are no
80 * '[...]' character ranges and '*' and '?' can not
81 * be escaped to include them literally in a pattern.
82 * When multiple strings must be matched against the same pattern, it
83 * is better to compile the pattern to a GPatternSpec using
84 * g_pattern_spec_new() and use g_pattern_match_string() instead of
85 * g_pattern_match_simple(). This avoids the overhead of repeated
86 * pattern compilation.
88 public class Pattern
91 /** the main Gtk struct */
92 protected GPatternSpec* gPatternSpec;
95 public GPatternSpec* getPatternStruct()
97 return gPatternSpec;
101 /** the main Gtk struct as a void* */
102 protected void* getStruct()
104 return cast(void*)gPatternSpec;
108 * Sets our main struct and passes it to the parent class
110 public this (GPatternSpec* gPatternSpec)
112 version(noAssert)
114 if ( gPatternSpec is null )
116 int zero = 0;
117 version(Tango)
119 Stdout("struct gPatternSpec is null on constructor").newline;
121 else
123 printf("struct gPatternSpec is null on constructor");
125 zero = zero / zero;
128 else
130 assert(gPatternSpec !is null, "struct gPatternSpec is null on constructor");
132 this.gPatternSpec = gPatternSpec;
140 * Compiles a pattern to a GPatternSpec.
141 * pattern:
142 * a zero-terminated UTF-8 encoded string.
143 * Returns:
144 * a newly-allocated GPatternSpec.
146 public this (char[] pattern)
148 // GPatternSpec* g_pattern_spec_new (const gchar *pattern);
149 this(cast(GPatternSpec*)g_pattern_spec_new(Str.toStringz(pattern)) );
153 * Frees the memory allocated for the GPatternSpec.
154 * pspec:
155 * a GPatternSpec.
157 public void free()
159 // void g_pattern_spec_free (GPatternSpec *pspec);
160 g_pattern_spec_free(gPatternSpec);
164 * Compares two compiled pattern specs and returns whether they
165 * will match the same set of strings.
166 * pspec1:
167 * a GPatternSpec.
168 * pspec2:
169 * another GPatternSpec.
170 * Returns:
171 * Whether the compiled patterns are equal.
173 public int equal(Pattern pspec2)
175 // gboolean g_pattern_spec_equal (GPatternSpec *pspec1, GPatternSpec *pspec2);
176 return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct());
180 * Matches a string against a compiled pattern. Passing the correct length of the
181 * string given is mandatory. The reversed string can be omitted by passing NULL,
182 * this is more efficient if the reversed version of the string to be matched is
183 * not at hand, as g_pattern_match() will only construct it if the compiled pattern
184 * requires reverse matches.
185 * Note that, if the user code will (possibly) match a string against a multitude
186 * of patterns containing wildcards, chances are high that some patterns will
187 * require a reversed string. In this case, it's more efficient to provide the
188 * reversed string to avoid multiple constructions thereof in the various calls to
189 * g_pattern_match().
190 * Note also that the reverse of a UTF-8 encoded string can in general
191 * not be obtained by g_strreverse().
192 * This works only if the string doesn't contain any multibyte characters.
193 * Glib offers the g_utf_strreverse() function to reverse UTF-8 encoded strings.
194 * pspec:
195 * a GPatternSpec.
196 * string_length:
197 * the length of string.
198 * string:
199 * the UTF-8 encoded string to match.
200 * string_reversed:
201 * the reverse of string or NULL.
202 * Returns:
203 * TRUE if string matches pspec.
205 public int gPatternMatch(uint stringLength, char[] string, char[] stringReversed)
207 // gboolean g_pattern_match (GPatternSpec *pspec, guint string_length, const gchar *string, const gchar *string_reversed);
208 return g_pattern_match(gPatternSpec, stringLength, Str.toStringz(string), Str.toStringz(stringReversed));
212 * Matches a string against a compiled pattern. If the string is to
213 * be matched against more than one pattern, consider using
214 * g_pattern_match() instead while supplying the reversed string.
215 * pspec:
216 * a GPatternSpec.
217 * string:
218 * the UTF-8 encoded string to match.
219 * Returns:
220 * TRUE if string matches pspec.
222 public int string(char[] string)
224 // gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
225 return g_pattern_match_string(gPatternSpec, Str.toStringz(string));
229 * Matches a string against a pattern given as a string.
230 * If this function is to be called in a loop, it's more efficient to compile
231 * the pattern once with g_pattern_spec_new() and call g_pattern_match_string()
232 * repetively.
233 * pattern:
234 * the UTF-8 encoded pattern.
235 * string:
236 * the UTF-8 encoded string to match.
237 * Returns:
238 * TRUE if string matches pspec.
240 public static int simple(char[] pattern, char[] string)
242 // gboolean g_pattern_match_simple (const gchar *pattern, const gchar *string);
243 return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(string));