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