1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// A `GPatternSpec` struct is the ‘compiled’ form of a glob-style pattern.
15//
16// The [func@GLib.pattern_match_simple] and [method@GLib.PatternSpec.match] functions
17// match a string against a pattern containing `*` and `?` wildcards with similar
18// semantics as the standard `glob()` function: `*` matches an arbitrary,
19// possibly empty, string, `?` matches an arbitrary character.
20//
21// Note that in contrast to [`glob()`](man:glob(3)), the `/` character can be
22// matched by the wildcards, there are no `[…]` character ranges and `*` and `?`
23// can not be escaped to include them literally in a pattern.
24//
25// When multiple strings must be matched against the same pattern, it is better
26// to compile the pattern to a [struct@GLib.PatternSpec] using
27// [ctor@GLib.PatternSpec.new] and use [method@GLib.PatternSpec.match_string]
28// instead of [func@GLib.pattern_match_simple]. This avoids the overhead of repeated
29// pattern compilation.
30type PatternSpec struct {
31 _ structs.HostLayout
32}
33
34var xPatternSpecGLibType func() types.GType
35
36func PatternSpecGLibType() types.GType {
37 return xPatternSpecGLibType()
38}
39
40func (x *PatternSpec) GoPointer() uintptr {
41 return uintptr(unsafe.Pointer(x))
42}
43
44var xNewPatternSpec func(string) *PatternSpec
45
46// Compiles a pattern to a [type@GLib.PatternSpec].
47func NewPatternSpec(PatternVar string) *PatternSpec {
48
49 cret := xNewPatternSpec(PatternVar)
50 return cret
51}
52
53var xPatternSpecCopy func(uintptr) *PatternSpec
54
55// Copies @pspec in a new [type@GLib.PatternSpec].
56func (x *PatternSpec) Copy() *PatternSpec {
57
58 cret := xPatternSpecCopy(x.GoPointer())
59 return cret
60}
61
62var xPatternSpecEqual func(uintptr, *PatternSpec) bool
63
64// Compares two compiled pattern specs and returns whether they will
65// match the same set of strings.
66func (x *PatternSpec) Equal(Pspec2Var *PatternSpec) bool {
67
68 cret := xPatternSpecEqual(x.GoPointer(), Pspec2Var)
69 return cret
70}
71
72var xPatternSpecFree func(uintptr)
73
74// Frees the memory allocated for the [type@GLib.PatternSpec].
75func (x *PatternSpec) Free() {
76
77 xPatternSpecFree(x.GoPointer())
78
79}
80
81var xPatternSpecMatch func(uintptr, uint, string, uintptr) bool
82
83// Matches a string against a compiled pattern.
84//
85// Passing the correct
86// length of the string given is mandatory. The reversed string can be
87// omitted by passing `NULL`, this is more efficient if the reversed
88// version of the string to be matched is not at hand, as
89// [method@GLib.PatternSpec.match] will only construct it if the compiled pattern
90// requires reverse matches.
91//
92// Note that, if the user code will (possibly) match a string against a
93// multitude of patterns containing wildcards, chances are high that
94// some patterns will require a reversed string. In this case, it’s
95// more efficient to provide the reversed string to avoid multiple
96// constructions thereof in the various calls to [method@GLib.PatternSpec.match].
97//
98// Note also that the reverse of a UTF-8 encoded string can in general
99// not be obtained by [func@GLib.strreverse]. This works only if the string
100// does not contain any multibyte characters. GLib offers the
101// [func@GLib.utf8_strreverse] function to reverse UTF-8 encoded strings.
102func (x *PatternSpec) Match(StringLengthVar uint, StringVar string, StringReversedVar *string) bool {
103
104 StringReversedVarPtr := core.GStrdupNullable(StringReversedVar)
105 defer core.GFreeNullable(StringReversedVarPtr)
106
107 cret := xPatternSpecMatch(x.GoPointer(), StringLengthVar, StringVar, StringReversedVarPtr)
108 return cret
109}
110
111var xPatternSpecMatchString func(uintptr, string) bool
112
113// Matches a string against a compiled pattern.
114//
115// If the string is to be
116// matched against more than one pattern, consider using
117// [method@GLib.PatternSpec.match] instead while supplying the reversed string.
118func (x *PatternSpec) MatchString(StringVar string) bool {
119
120 cret := xPatternSpecMatchString(x.GoPointer(), StringVar)
121 return cret
122}
123
124var xPatternMatch func(*PatternSpec, uint, string, uintptr) bool
125
126// Matches a string against a compiled pattern.
127//
128// Passing the correct
129// length of the string given is mandatory. The reversed string can be
130// omitted by passing `NULL`, this is more efficient if the reversed
131// version of the string to be matched is not at hand, as
132// `g_pattern_match()` will only construct it if the compiled pattern
133// requires reverse matches.
134//
135// Note that, if the user code will (possibly) match a string against a
136// multitude of patterns containing wildcards, chances are high that
137// some patterns will require a reversed string. In this case, it’s
138// more efficient to provide the reversed string to avoid multiple
139// constructions thereof in the various calls to `g_pattern_match()`.
140//
141// Note also that the reverse of a UTF-8 encoded string can in general
142// not be obtained by [func@GLib.strreverse]. This works only if the string
143// does not contain any multibyte characters. GLib offers the
144// [func@GLib.utf8_strreverse] function to reverse UTF-8 encoded strings.
145func PatternMatch(PspecVar *PatternSpec, StringLengthVar uint, StringVar string, StringReversedVar *string) bool {
146
147 StringReversedVarPtr := core.GStrdupNullable(StringReversedVar)
148 defer core.GFreeNullable(StringReversedVarPtr)
149
150 cret := xPatternMatch(PspecVar, StringLengthVar, StringVar, StringReversedVarPtr)
151
152 return cret
153}
154
155var xPatternMatchSimple func(string, string) bool
156
157// Matches a string against a pattern given as a string.
158//
159// If this
160// function is to be called in a loop, it’s more efficient to compile
161// the pattern once with [ctor@GLib.PatternSpec.new] and call
162// [method@GLib.PatternSpec.match_string] repeatedly.
163func PatternMatchSimple(PatternVar string, StringVar string) bool {
164
165 cret := xPatternMatchSimple(PatternVar, StringVar)
166
167 return cret
168}
169
170var xPatternMatchString func(*PatternSpec, string) bool
171
172// Matches a string against a compiled pattern.
173//
174// If the string is to be
175// matched against more than one pattern, consider using
176// [method@GLib.PatternSpec.match] instead while supplying the reversed string.
177func PatternMatchString(PspecVar *PatternSpec, StringVar string) bool {
178
179 cret := xPatternMatchString(PspecVar, StringVar)
180
181 return cret
182}
183
184func init() {
185 core.SetPackageName("GLIB", "glib-2.0")
186 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
187 var libs []uintptr
188 for _, libPath := range core.GetPaths("GLIB") {
189 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
190 if err != nil {
191 panic(err)
192 }
193 libs = append(libs, lib)
194 }
195
196 core.PuregoSafeRegister(&xPatternMatch, libs, "g_pattern_match")
197 core.PuregoSafeRegister(&xPatternMatchSimple, libs, "g_pattern_match_simple")
198 core.PuregoSafeRegister(&xPatternMatchString, libs, "g_pattern_match_string")
199
200 core.PuregoSafeRegister(&xPatternSpecGLibType, libs, "g_pattern_spec_get_type")
201
202 core.PuregoSafeRegister(&xNewPatternSpec, libs, "g_pattern_spec_new")
203
204 core.PuregoSafeRegister(&xPatternSpecCopy, libs, "g_pattern_spec_copy")
205 core.PuregoSafeRegister(&xPatternSpecEqual, libs, "g_pattern_spec_equal")
206 core.PuregoSafeRegister(&xPatternSpecFree, libs, "g_pattern_spec_free")
207 core.PuregoSafeRegister(&xPatternSpecMatch, libs, "g_pattern_spec_match")
208 core.PuregoSafeRegister(&xPatternSpecMatchString, libs, "g_pattern_spec_match_string")
209
210}