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