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