alternative to assert
[gtkD.git] / src / glib / Pattern.d
blobad1cbeac0f6ac00f5378dbcd61c0fcb5d6b3cda9
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 * local aliases:
51 module glib.Pattern;
53 private import glib.glibtypes;
55 private import lib.glib;
57 private import glib.Str;
59 /**
60 * Description
61 * The g_pattern_match* functions match a string
62 * against a pattern containing '*' and '?' wildcards with similar semantics
63 * as the standard glob() function: '*' matches an arbitrary, possibly empty,
64 * string, '?' matches an arbitrary character.
65 * Note that in contrast to glob(), the '/' character
66 * can be matched by the wildcards, there are no
67 * '[...]' character ranges and '*' and '?' can not
68 * be escaped to include them literally in a pattern.
69 * When multiple strings must be matched against the same pattern, it
70 * is better to compile the pattern to a GPatternSpec using
71 * g_pattern_spec_new() and use g_pattern_match_string() instead of
72 * g_pattern_match_simple(). This avoids the overhead of repeated
73 * pattern compilation.
75 public class Pattern
78 /** the main Gtk struct */
79 protected GPatternSpec* gPatternSpec;
82 public GPatternSpec* getPatternStruct()
84 return gPatternSpec;
88 /** the main Gtk struct as a void* */
89 protected void* getStruct()
91 return cast(void*)gPatternSpec;
94 /**
95 * Sets our main struct and passes it to the parent class
97 public this (GPatternSpec* gPatternSpec)
99 this.gPatternSpec = gPatternSpec;
107 * Compiles a pattern to a GPatternSpec.
108 * pattern:
109 * a zero-terminated UTF-8 encoded string.
110 * Returns:
111 * a newly-allocated GPatternSpec.
113 public this (char[] pattern)
115 // GPatternSpec* g_pattern_spec_new (const gchar *pattern);
116 this(cast(GPatternSpec*)g_pattern_spec_new(Str.toStringz(pattern)) );
120 * Frees the memory allocated for the GPatternSpec.
121 * pspec:
122 * a GPatternSpec.
124 public void free()
126 // void g_pattern_spec_free (GPatternSpec *pspec);
127 g_pattern_spec_free(gPatternSpec);
131 * Compares two compiled pattern specs and returns whether they
132 * will match the same set of strings.
133 * pspec1:
134 * a GPatternSpec.
135 * pspec2:
136 * another GPatternSpec.
137 * Returns:
138 * Whether the compiled patterns are equal.
140 public int equal(Pattern pspec2)
142 // gboolean g_pattern_spec_equal (GPatternSpec *pspec1, GPatternSpec *pspec2);
143 return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct());
147 * Matches a string against a compiled pattern. Passing the correct length of the
148 * string given is mandatory. The reversed string can be omitted by passing NULL,
149 * this is more efficient if the reversed version of the string to be matched is
150 * not at hand, as g_pattern_match() will only construct it if the compiled pattern
151 * requires reverse matches.
152 * Note that, if the user code will (possibly) match a string against a multitude
153 * of patterns containing wildcards, chances are high that some patterns will
154 * require a reversed string. In this case, it's more efficient to provide the
155 * reversed string to avoid multiple constructions thereof in the various calls to
156 * g_pattern_match().
157 * Note also that the reverse of a UTF-8 encoded string can in general
158 * not be obtained by g_strreverse().
159 * This works only if the string doesn't contain any multibyte characters.
160 * Glib offers the g_utf_strreverse() function to reverse UTF-8 encoded strings.
161 * pspec:
162 * a GPatternSpec.
163 * string_length:
164 * the length of string.
165 * string:
166 * the UTF-8 encoded string to match.
167 * string_reversed:
168 * the reverse of string or NULL.
169 * Returns:
170 * TRUE if string matches pspec.
172 public int gPatternMatch(uint stringLength, char[] string, char[] stringReversed)
174 // gboolean g_pattern_match (GPatternSpec *pspec, guint string_length, const gchar *string, const gchar *string_reversed);
175 return g_pattern_match(gPatternSpec, stringLength, Str.toStringz(string), Str.toStringz(stringReversed));
179 * Matches a string against a compiled pattern. If the string is to
180 * be matched against more than one pattern, consider using
181 * g_pattern_match() instead while supplying the reversed string.
182 * pspec:
183 * a GPatternSpec.
184 * string:
185 * the UTF-8 encoded string to match.
186 * Returns:
187 * TRUE if string matches pspec.
189 public int string(char[] string)
191 // gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
192 return g_pattern_match_string(gPatternSpec, Str.toStringz(string));
196 * Matches a string against a pattern given as a string.
197 * If this function is to be called in a loop, it's more efficient to compile
198 * the pattern once with g_pattern_spec_new() and call g_pattern_match_string()
199 * repetively.
200 * pattern:
201 * the UTF-8 encoded pattern.
202 * string:
203 * the UTF-8 encoded string to match.
204 * Returns:
205 * TRUE if string matches pspec.
207 public static int simple(char[] pattern, char[] string)
209 // gboolean g_pattern_match_simple (const gchar *pattern, const gchar *string);
210 return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(string));