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 module glib.Pattern; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 public import glib.c.types; 31 private import gtkd.Loader; 32 33 34 /** 35 * A GPatternSpec struct is the 'compiled' form of a pattern. This 36 * structure is opaque and its fields cannot be accessed directly. 37 */ 38 public class Pattern 39 { 40 /** the main Gtk struct */ 41 protected GPatternSpec* gPatternSpec; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GPatternSpec* getPatternStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gPatternSpec; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gPatternSpec; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GPatternSpec* gPatternSpec, bool ownedRef = false) 62 { 63 this.gPatternSpec = gPatternSpec; 64 this.ownedRef = ownedRef; 65 } 66 67 ~this () 68 { 69 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 70 g_pattern_spec_free(gPatternSpec); 71 } 72 73 74 /** 75 * Compares two compiled pattern specs and returns whether they will 76 * match the same set of strings. 77 * 78 * Params: 79 * pspec2 = another #GPatternSpec 80 * 81 * Returns: Whether the compiled patterns are equal 82 */ 83 public bool equal(Pattern pspec2) 84 { 85 return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct()) != 0; 86 } 87 88 /** 89 * Frees the memory allocated for the #GPatternSpec. 90 */ 91 public void free() 92 { 93 g_pattern_spec_free(gPatternSpec); 94 ownedRef = false; 95 } 96 97 /** 98 * Compiles a pattern to a #GPatternSpec. 99 * 100 * Params: 101 * pattern = a zero-terminated UTF-8 encoded string 102 * 103 * Returns: a newly-allocated #GPatternSpec 104 * 105 * Throws: ConstructionException GTK+ fails to create the object. 106 */ 107 public this(string pattern) 108 { 109 auto __p = g_pattern_spec_new(Str.toStringz(pattern)); 110 111 if(__p is null) 112 { 113 throw new ConstructionException("null returned by new"); 114 } 115 116 this(cast(GPatternSpec*) __p); 117 } 118 119 /** 120 * Matches a string against a compiled pattern. Passing the correct 121 * length of the string given is mandatory. The reversed string can be 122 * omitted by passing %NULL, this is more efficient if the reversed 123 * version of the string to be matched is not at hand, as 124 * g_pattern_match() will only construct it if the compiled pattern 125 * requires reverse matches. 126 * 127 * Note that, if the user code will (possibly) match a string against a 128 * multitude of patterns containing wildcards, chances are high that 129 * some patterns will require a reversed string. In this case, it's 130 * more efficient to provide the reversed string to avoid multiple 131 * constructions thereof in the various calls to g_pattern_match(). 132 * 133 * Note also that the reverse of a UTF-8 encoded string can in general 134 * not be obtained by g_strreverse(). This works only if the string 135 * does not contain any multibyte characters. GLib offers the 136 * g_utf8_strreverse() function to reverse UTF-8 encoded strings. 137 * 138 * Params: 139 * pspec = a #GPatternSpec 140 * stringLength = the length of @string (in bytes, i.e. strlen(), 141 * not g_utf8_strlen()) 142 * string_ = the UTF-8 encoded string to match 143 * stringReversed = the reverse of @string or %NULL 144 * 145 * Returns: %TRUE if @string matches @pspec 146 */ 147 public static bool patternMatch(Pattern pspec, uint stringLength, string string_, string stringReversed) 148 { 149 return g_pattern_match((pspec is null) ? null : pspec.getPatternStruct(), stringLength, Str.toStringz(string_), Str.toStringz(stringReversed)) != 0; 150 } 151 152 /** 153 * Matches a string against a pattern given as a string. If this 154 * function is to be called in a loop, it's more efficient to compile 155 * the pattern once with g_pattern_spec_new() and call 156 * g_pattern_match_string() repeatedly. 157 * 158 * Params: 159 * pattern = the UTF-8 encoded pattern 160 * string_ = the UTF-8 encoded string to match 161 * 162 * Returns: %TRUE if @string matches @pspec 163 */ 164 public static bool patternMatchSimple(string pattern, string string_) 165 { 166 return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(string_)) != 0; 167 } 168 169 /** 170 * Matches a string against a compiled pattern. If the string is to be 171 * matched against more than one pattern, consider using 172 * g_pattern_match() instead while supplying the reversed string. 173 * 174 * Params: 175 * pspec = a #GPatternSpec 176 * string_ = the UTF-8 encoded string to match 177 * 178 * Returns: %TRUE if @string matches @pspec 179 */ 180 public static bool patternMatchString(Pattern pspec, string string_) 181 { 182 return g_pattern_match_string((pspec is null) ? null : pspec.getPatternStruct(), Str.toStringz(string_)) != 0; 183 } 184 }