source: appstream-generator/build/girepo/glib/Pattern.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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