1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "github.com/ebitengine/purego"
6
7 "github.com/bnema/puregotk/pkg/core"
8)
9
10// A typedef alias for gchar**. This is mostly useful when used together with
11// `g_auto()`.
12type Strv = string
13
14const (
15 // A good size for a buffer to be passed into [func@GLib.ascii_dtostr].
16 // It is guaranteed to be enough for all output of that function
17 // on systems with 64bit IEEE-compatible doubles.
18 //
19 // The typical usage would be something like:
20 // ```C
21 // char buf[G_ASCII_DTOSTR_BUF_SIZE];
22 //
23 // fprintf (out, "value=%s\n", g_ascii_dtostr (buf, sizeof (buf), value));
24 // ```
25 ASCII_DTOSTR_BUF_SIZE int = 39
26 // The standard delimiters, used in [func@GLib.strdelimit].
27 STR_DELIMITERS string = "_-|> <."
28)
29
30type AsciiType int
31
32const (
33 GAsciiAlnumValue AsciiType = 1
34
35 GAsciiAlphaValue AsciiType = 2
36
37 GAsciiCntrlValue AsciiType = 4
38
39 GAsciiDigitValue AsciiType = 8
40
41 GAsciiGraphValue AsciiType = 16
42
43 GAsciiLowerValue AsciiType = 32
44
45 GAsciiPrintValue AsciiType = 64
46
47 GAsciiPunctValue AsciiType = 128
48
49 GAsciiSpaceValue AsciiType = 256
50
51 GAsciiUpperValue AsciiType = 512
52
53 GAsciiXdigitValue AsciiType = 1024
54)
55
56// Error codes returned by functions converting a string to a number.
57type NumberParserError int
58
59const (
60
61 // string was not a valid number
62 GNumberParserErrorInvalidValue NumberParserError = 0
63 // string was a number, but out of bounds
64 GNumberParserErrorOutOfBoundsValue NumberParserError = 1
65)
66
67var xAsciiDigitValue func(byte) int
68
69// Determines the numeric value of a character as a decimal digit. If the
70// character is not a decimal digit according to [func@GLib.ascii_isdigit],
71// `-1` is returned.
72//
73// Differs from [func@GLib.unichar_digit_value] because it takes a char, so
74// there's no worry about sign extension if characters are signed.
75func AsciiDigitValue(CVar byte) int {
76
77 cret := xAsciiDigitValue(CVar)
78
79 return cret
80}
81
82var xAsciiDtostr func(string, int, float64) string
83
84// Converts a `gdouble` to a string, using the '.' as
85// decimal point.
86//
87// This function generates enough precision that converting
88// the string back using [func@GLib.ascii_strtod] gives the same machine-number
89// (on machines with IEEE compatible 64bit doubles). It is
90// guaranteed that the size of the resulting string will never
91// be larger than [const@GLib.ASCII_DTOSTR_BUF_SIZE] bytes, including the terminating
92// nul character, which is always added.
93func AsciiDtostr(BufferVar string, BufLenVar int, DVar float64) string {
94
95 cret := xAsciiDtostr(BufferVar, BufLenVar, DVar)
96
97 return cret
98}
99
100var xAsciiFormatd func(string, int, string, float64) string
101
102// Converts a `gdouble` to a string, using the '.' as
103// decimal point. To format the number you pass in
104// a `printf()`-style format string. Allowed conversion
105// specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'.
106//
107// The @format must just be a single format specifier
108// starting with `%`, expecting a `gdouble` argument.
109//
110// The returned buffer is guaranteed to be nul-terminated.
111//
112// If you just want to want to serialize the value into a
113// string, use [func@GLib.ascii_dtostr].
114func AsciiFormatd(BufferVar string, BufLenVar int, FormatVar string, DVar float64) string {
115
116 cret := xAsciiFormatd(BufferVar, BufLenVar, FormatVar, DVar)
117
118 return cret
119}
120
121var xAsciiStrcasecmp func(string, string) int
122
123// Compare two strings, ignoring the case of ASCII characters.
124//
125// Unlike the BSD `strcasecmp()` function, this only recognizes standard
126// ASCII letters and ignores the locale, treating all non-ASCII
127// bytes as if they are not letters.
128//
129// This function should be used only on strings that are known to be
130// in encodings where the bytes corresponding to ASCII letters always
131// represent themselves. This includes UTF-8 and the ISO-8859-*
132// charsets, but not for instance double-byte encodings like the
133// Windows Codepage 932, where the trailing bytes of double-byte
134// characters include all ASCII letters. If you compare two CP932
135// strings using this function, you will get false matches.
136//
137// Both @s1 and @s2 must be non-`NULL`.
138func AsciiStrcasecmp(S1Var string, S2Var string) int {
139
140 cret := xAsciiStrcasecmp(S1Var, S2Var)
141
142 return cret
143}
144
145var xAsciiStrdown func(string, int) string
146
147// Converts all upper case ASCII letters to lower case ASCII letters, with
148// semantics that exactly match [func@GLib.ascii_tolower].
149func AsciiStrdown(StrVar string, LenVar int) string {
150
151 cret := xAsciiStrdown(StrVar, LenVar)
152
153 return cret
154}
155
156var xAsciiStringToSigned func(string, uint, int64, int64, *int64, **Error) bool
157
158// A convenience function for converting a string to a signed number.
159//
160// This function assumes that @str contains only a number of the given
161// @base that is within inclusive bounds limited by @min and @max. If
162// this is true, then the converted number is stored in @out_num. An
163// empty string is not a valid input. A string with leading or
164// trailing whitespace is also an invalid input.
165//
166// @base can be between 2 and 36 inclusive. Hexadecimal numbers must
167// not be prefixed with "0x" or "0X". Such a problem does not exist
168// for octal numbers, since they were usually prefixed with a zero
169// which does not change the value of the parsed number.
170//
171// Parsing failures result in an error with the `G_NUMBER_PARSER_ERROR`
172// domain. If the input is invalid, the error code will be
173// [error@GLib.NumberParserError.INVALID]. If the parsed number is out of
174// bounds - [error@GLib.NumberParserError.OUT_OF_BOUNDS].
175//
176// See [func@GLib.ascii_strtoll] if you have more complex needs such as
177// parsing a string which starts with a number, but then has other
178// characters.
179func AsciiStringToSigned(StrVar string, BaseVar uint, MinVar int64, MaxVar int64, OutNumVar *int64) (bool, error) {
180 var cerr *Error
181
182 cret := xAsciiStringToSigned(StrVar, BaseVar, MinVar, MaxVar, OutNumVar, &cerr)
183
184 if cerr == nil {
185 return cret, nil
186 }
187 return cret, cerr
188
189}
190
191var xAsciiStringToUnsigned func(string, uint, uint64, uint64, *uint64, **Error) bool
192
193// A convenience function for converting a string to an unsigned number.
194//
195// This function assumes that @str contains only a number of the given
196// @base that is within inclusive bounds limited by @min and @max. If
197// this is true, then the converted number is stored in @out_num. An
198// empty string is not a valid input. A string with leading or
199// trailing whitespace is also an invalid input. A string with a leading sign
200// (`-` or `+`) is not a valid input for the unsigned parser.
201//
202// @base can be between 2 and 36 inclusive. Hexadecimal numbers must
203// not be prefixed with "0x" or "0X". Such a problem does not exist
204// for octal numbers, since they were usually prefixed with a zero
205// which does not change the value of the parsed number.
206//
207// Parsing failures result in an error with the `G_NUMBER_PARSER_ERROR`
208// domain. If the input is invalid, the error code will be
209// [error@GLib.NumberParserError.INVALID]. If the parsed number is out of
210// bounds - [error@GLib.NumberParserError.OUT_OF_BOUNDS].
211//
212// See [func@GLib.ascii_strtoull] if you have more complex needs such as
213// parsing a string which starts with a number, but then has other
214// characters.
215func AsciiStringToUnsigned(StrVar string, BaseVar uint, MinVar uint64, MaxVar uint64, OutNumVar *uint64) (bool, error) {
216 var cerr *Error
217
218 cret := xAsciiStringToUnsigned(StrVar, BaseVar, MinVar, MaxVar, OutNumVar, &cerr)
219
220 if cerr == nil {
221 return cret, nil
222 }
223 return cret, cerr
224
225}
226
227var xAsciiStrncasecmp func(string, string, uint) int
228
229// Compare @s1 and @s2, ignoring the case of ASCII characters and any
230// characters after the first @n in each string. If either string is
231// less than @n bytes long, comparison will stop at the first nul byte
232// encountered.
233//
234// Unlike the BSD `strncasecmp()` function, this only recognizes standard
235// ASCII letters and ignores the locale, treating all non-ASCII
236// characters as if they are not letters.
237//
238// The same warning as in [func@GLib.ascii_strcasecmp] applies: Use this
239// function only on strings known to be in encodings where bytes
240// corresponding to ASCII letters always represent themselves.
241func AsciiStrncasecmp(S1Var string, S2Var string, NVar uint) int {
242
243 cret := xAsciiStrncasecmp(S1Var, S2Var, NVar)
244
245 return cret
246}
247
248var xAsciiStrtod func(string, *string) float64
249
250// Converts a string to a floating point value.
251//
252// This function behaves like the standard `strtod()` function
253// does in the C locale. It does this without actually changing
254// the current locale, since that would not be thread-safe.
255// A limitation of the implementation is that this function
256// will still accept localized versions of infinities and NANs.
257//
258// This function is typically used when reading configuration
259// files or other non-user input that should be locale independent.
260// To handle input from the user you should normally use the
261// locale-sensitive system `strtod()` function.
262//
263// To convert from a gdouble to a string in a locale-insensitive
264// way, use [func@GLib.ascii_dtostr].
265//
266// If the correct value would cause overflow, plus or minus `HUGE_VAL`
267// is returned (according to the sign of the value), and `ERANGE` is
268// stored in `errno`. If the correct value would cause underflow,
269// zero is returned and `ERANGE` is stored in `errno`.
270//
271// This function resets `errno` before calling `strtod()` so that
272// you can reliably detect overflow and underflow.
273func AsciiStrtod(NptrVar string, EndptrVar *string) float64 {
274
275 cret := xAsciiStrtod(NptrVar, EndptrVar)
276
277 return cret
278}
279
280var xAsciiStrtoll func(string, *string, uint) int64
281
282// Converts a string to a `gint64` value.
283//
284// This function behaves like the standard `strtoll()` function
285// does in the C locale. It does this without actually
286// changing the current locale, since that would not be
287// thread-safe.
288//
289// This function is typically used when reading configuration
290// files or other non-user input that should be locale independent.
291// To handle input from the user you should normally use the
292// locale-sensitive system `strtoll()` function.
293//
294// If the correct value would cause overflow, [const@GLib.MAXINT64] or
295// [const@GLib.MININT64] is returned, and `ERANGE` is stored in `errno`.
296// If the base is outside the valid range, zero is returned, and
297// `EINVAL` is stored in `errno`. If the
298// string conversion fails, zero is returned, and @endptr returns @nptr
299// (if @endptr is non-`NULL`).
300func AsciiStrtoll(NptrVar string, EndptrVar *string, BaseVar uint) int64 {
301
302 cret := xAsciiStrtoll(NptrVar, EndptrVar, BaseVar)
303
304 return cret
305}
306
307var xAsciiStrtoull func(string, *string, uint) uint64
308
309// Converts a string to a `guint64` value.
310//
311// This function behaves like the standard `strtoull()` function
312// does in the C locale. It does this without actually
313// changing the current locale, since that would not be
314// thread-safe.
315//
316// Note that input with a leading minus sign (`-`) is accepted, and will return
317// the negation of the parsed number, unless that would overflow a `guint64`.
318// Critically, this means you cannot assume that a short fixed length input will
319// result in a low return value, as the input could have a leading `-`.
320//
321// This function is typically used when reading configuration
322// files or other non-user input that should be locale independent.
323// To handle input from the user you should normally use the
324// locale-sensitive system `strtoull()` function.
325//
326// If the correct value would cause overflow, [const@GLib.MAXUINT64]
327// is returned, and `ERANGE` is stored in `errno`.
328// If the base is outside the valid range, zero is returned, and
329// `EINVAL` is stored in `errno`.
330// If the string conversion fails, zero is returned, and @endptr returns
331// @nptr (if @endptr is non-`NULL`).
332func AsciiStrtoull(NptrVar string, EndptrVar *string, BaseVar uint) uint64 {
333
334 cret := xAsciiStrtoull(NptrVar, EndptrVar, BaseVar)
335
336 return cret
337}
338
339var xAsciiStrup func(string, int) string
340
341// Converts all lower case ASCII letters to upper case ASCII letters, with
342// semantics that exactly match [func@GLib.ascii_toupper].
343func AsciiStrup(StrVar string, LenVar int) string {
344
345 cret := xAsciiStrup(StrVar, LenVar)
346
347 return cret
348}
349
350var xAsciiTolower func(byte) byte
351
352// Convert a character to ASCII lower case. If the character is not an
353// ASCII upper case letter, it is returned unchanged.
354//
355// Unlike the standard C library `tolower()` function, this only
356// recognizes standard ASCII letters and ignores the locale, returning
357// all non-ASCII characters unchanged, even if they are lower case
358// letters in a particular character set. Also unlike the standard
359// library function, this takes and returns a char, not an int, so
360// don't call it on `EOF` but no need to worry about casting to `guchar`
361// before passing a possibly non-ASCII character in.
362func AsciiTolower(CVar byte) byte {
363
364 cret := xAsciiTolower(CVar)
365
366 return cret
367}
368
369var xAsciiToupper func(byte) byte
370
371// Convert a character to ASCII upper case. If the character is not an
372// ASCII lower case letter, it is returned unchanged.
373//
374// Unlike the standard C library `toupper()` function, this only
375// recognizes standard ASCII letters and ignores the locale, returning
376// all non-ASCII characters unchanged, even if they are upper case
377// letters in a particular character set. Also unlike the standard
378// library function, this takes and returns a char, not an int, so
379// don't call it on `EOF` but no need to worry about casting to `guchar`
380// before passing a possibly non-ASCII character in.
381func AsciiToupper(CVar byte) byte {
382
383 cret := xAsciiToupper(CVar)
384
385 return cret
386}
387
388var xAsciiXdigitValue func(byte) int
389
390// Determines the numeric value of a character as a hexadecimal digit. If the
391// character is not a hex digit according to [func@GLib.ascii_isxdigit],
392// `-1` is returned.
393//
394// Differs from [func@GLib.unichar_xdigit_value] because it takes a char, so
395// there's no worry about sign extension if characters are signed.
396//
397// Differs from [func@GLib.unichar_xdigit_value] because it takes a char, so
398// there's no worry about sign extension if characters are signed.
399func AsciiXdigitValue(CVar byte) int {
400
401 cret := xAsciiXdigitValue(CVar)
402
403 return cret
404}
405
406var xMemdup func(uintptr, uint) uintptr
407
408// Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
409// from @mem. If @mem is `NULL` it returns `NULL`.
410func Memdup(MemVar uintptr, ByteSizeVar uint) uintptr {
411
412 cret := xMemdup(MemVar, ByteSizeVar)
413
414 return cret
415}
416
417var xMemdup2 func(uintptr, uint) uintptr
418
419// Allocates @byte_size bytes of memory, and copies @byte_size bytes into it
420// from @mem. If @mem is `NULL` it returns `NULL`.
421//
422// This replaces [func@GLib.memdup], which was prone to integer overflows when
423// converting the argument from a `gsize` to a `guint`.
424func Memdup2(MemVar uintptr, ByteSizeVar uint) uintptr {
425
426 cret := xMemdup2(MemVar, ByteSizeVar)
427
428 return cret
429}
430
431var xStpcpy func(string, string) string
432
433// Copies a nul-terminated string into the destination buffer, including
434// the trailing nul byte, and returns a pointer to the trailing nul byte
435// in `dest`. The return value is useful for concatenating multiple
436// strings without having to repeatedly scan for the end.
437func Stpcpy(DestVar string, SrcVar string) string {
438
439 cret := xStpcpy(DestVar, SrcVar)
440
441 return cret
442}
443
444var xStrHasPrefix func(string, string) bool
445
446// Looks whether the string @str begins with @prefix.
447func StrHasPrefix(StrVar string, PrefixVar string) bool {
448
449 cret := xStrHasPrefix(StrVar, PrefixVar)
450
451 return cret
452}
453
454var xStrHasSuffix func(string, string) bool
455
456// Looks whether a string ends with @suffix.
457func StrHasSuffix(StrVar string, SuffixVar string) bool {
458
459 cret := xStrHasSuffix(StrVar, SuffixVar)
460
461 return cret
462}
463
464var xStrIsAscii func(string) bool
465
466// Determines if a string is pure ASCII. A string is pure ASCII if it
467// contains no bytes with the high bit set.
468func StrIsAscii(StrVar string) bool {
469
470 cret := xStrIsAscii(StrVar)
471
472 return cret
473}
474
475var xStrMatchString func(string, string, bool) bool
476
477// Checks if a search conducted for @search_term should match
478// @potential_hit.
479//
480// This function calls [func@GLib.str_tokenize_and_fold] on both
481// @search_term and @potential_hit. ASCII alternates are never taken
482// for @search_term but will be taken for @potential_hit according to
483// the value of @accept_alternates.
484//
485// A hit occurs when each folded token in @search_term is a prefix of a
486// folded token from @potential_hit.
487//
488// Depending on how you're performing the search, it will typically be
489// faster to call `g_str_tokenize_and_fold()` on each string in
490// your corpus and build an index on the returned folded tokens, then
491// call `g_str_tokenize_and_fold()` on the search term and
492// perform lookups into that index.
493//
494// As some examples, searching for ‘fred’ would match the potential hit
495// ‘Smith, Fred’ and also ‘Frédéric’. Searching for ‘Fréd’ would match
496// ‘Frédéric’ but not ‘Frederic’ (due to the one-directional nature of
497// accent matching). Searching ‘fo’ would match ‘Foo’ and ‘Bar Foo
498// Baz’, but not ‘SFO’ (because no word has ‘fo’ as a prefix).
499func StrMatchString(SearchTermVar string, PotentialHitVar string, AcceptAlternatesVar bool) bool {
500
501 cret := xStrMatchString(SearchTermVar, PotentialHitVar, AcceptAlternatesVar)
502
503 return cret
504}
505
506var xStrToAscii func(string, uintptr) string
507
508// Transliterate @str to plain ASCII.
509//
510// For best results, @str should be in composed normalised form.
511//
512// This function performs a reasonably good set of character
513// replacements. The particular set of replacements that is done may
514// change by version or even by runtime environment.
515//
516// If the source language of @str is known, it can used to improve the
517// accuracy of the translation by passing it as @from_locale. It should
518// be a valid POSIX locale string (of the form
519// `language[_territory][.codeset][@modifier]`).
520//
521// If @from_locale is %NULL then the current locale is used.
522//
523// If you want to do translation for no specific locale, and you want it
524// to be done independently of the currently locale, specify `"C"` for
525// @from_locale.
526func StrToAscii(StrVar string, FromLocaleVar *string) string {
527
528 FromLocaleVarPtr := core.GStrdupNullable(FromLocaleVar)
529 defer core.GFreeNullable(FromLocaleVarPtr)
530
531 cret := xStrToAscii(StrVar, FromLocaleVarPtr)
532
533 return cret
534}
535
536var xStrTokenizeAndFold func(string, uintptr, *[]string) []string
537
538// Tokenizes @string and performs folding on each token.
539//
540// A token is a non-empty sequence of alphanumeric characters in the
541// source string, separated by non-alphanumeric characters. An
542// "alphanumeric" character for this purpose is one that matches
543// [func@GLib.unichar_isalnum] or [func@GLib.unichar_ismark].
544//
545// Each token is then (Unicode) normalised and case-folded. If
546// @ascii_alternates is non-`NULL` and some of the returned tokens
547// contain non-ASCII characters, ASCII alternatives will be generated.
548//
549// The number of ASCII alternatives that are generated and the method
550// for doing so is unspecified, but @translit_locale (if specified) may
551// improve the transliteration if the language of the source string is
552// known.
553func StrTokenizeAndFold(StringVar string, TranslitLocaleVar *string, AsciiAlternatesVar *[]string) []string {
554
555 TranslitLocaleVarPtr := core.GStrdupNullable(TranslitLocaleVar)
556 defer core.GFreeNullable(TranslitLocaleVarPtr)
557
558 cret := xStrTokenizeAndFold(StringVar, TranslitLocaleVarPtr, AsciiAlternatesVar)
559
560 return cret
561}
562
563var xStrcanon func(string, string, byte) string
564
565// For each character in @string, if the character is not in @valid_chars,
566// replaces the character with @substitutor.
567//
568// Modifies @string in place, and return @string itself, not a copy. The
569// return value is to allow nesting such as:
570// ```C
571// g_ascii_strup (g_strcanon (str, "abc", '?'))
572// ```
573//
574// In order to modify a copy, you may use [func@GLib.strdup]:
575// ```C
576// reformatted = g_strcanon (g_strdup (const_str), "abc", '?');
577// …
578// g_free (reformatted);
579// ```
580func Strcanon(StringVar string, ValidCharsVar string, SubstitutorVar byte) string {
581
582 cret := xStrcanon(StringVar, ValidCharsVar, SubstitutorVar)
583
584 return cret
585}
586
587var xStrcasecmp func(string, string) int
588
589// A case-insensitive string comparison, corresponding to the standard
590// `strcasecmp()` function on platforms which support it.
591func Strcasecmp(S1Var string, S2Var string) int {
592
593 cret := xStrcasecmp(S1Var, S2Var)
594
595 return cret
596}
597
598var xStrchomp func(string) string
599
600// Removes trailing whitespace from a string.
601//
602// This function doesn't allocate or reallocate any memory;
603// it modifies @string in place. Therefore, it cannot be used
604// on statically allocated strings.
605//
606// The pointer to @string is returned to allow the nesting of functions.
607//
608// Also see [func@GLib.strchug] and [func@GLib.strstrip].
609func Strchomp(StringVar string) string {
610
611 cret := xStrchomp(StringVar)
612
613 return cret
614}
615
616var xStrchug func(string) string
617
618// Removes leading whitespace from a string, by moving the rest
619// of the characters forward.
620//
621// This function doesn't allocate or reallocate any memory;
622// it modifies @string in place. Therefore, it cannot be used on
623// statically allocated strings.
624//
625// The pointer to @string is returned to allow the nesting of functions.
626//
627// Also see [func@GLib.strchomp] and [func@GLib.strstrip].
628func Strchug(StringVar string) string {
629
630 cret := xStrchug(StringVar)
631
632 return cret
633}
634
635var xStrcompress func(string) string
636
637// Makes a copy of a string replacing C string-style escape
638// sequences with their one byte equivalent:
639//
640// - `\b` → [U+0008 Backspace](https://en.wikipedia.org/wiki/Backspace)
641// - `\f` → [U+000C Form Feed](https://en.wikipedia.org/wiki/Form_feed)
642// - `\n` → [U+000A Line Feed](https://en.wikipedia.org/wiki/Newline)
643// - `\r` → [U+000D Carriage Return](https://en.wikipedia.org/wiki/Carriage_return)
644// - `\t` → [U+0009 Horizontal Tabulation](https://en.wikipedia.org/wiki/Tab_character)
645// - `\v` → [U+000B Vertical Tabulation](https://en.wikipedia.org/wiki/Vertical_Tab)
646// - `\` followed by one to three octal digits → the numeric value (mod 255)
647// - `\` followed by any other character → the character as is.
648// For example, `\\` will turn into a backslash (`\`) and `\"` into a double quote (`"`).
649//
650// [func@GLib.strescape] does the reverse conversion.
651func Strcompress(SourceVar string) string {
652
653 cret := xStrcompress(SourceVar)
654
655 return cret
656}
657
658var xStrconcat func(string, ...interface{}) string
659
660// Concatenates all of the given strings into one long string.
661//
662// The variable argument list must end with `NULL`. If you forget the `NULL`,
663// `g_strconcat()` will start appending random memory junk to your string.
664//
665// Note that this function is usually not the right function to use to
666// assemble a translated message from pieces, since proper translation
667// often requires the pieces to be reordered.
668func Strconcat(String1Var string, varArgs ...interface{}) string {
669
670 cret := xStrconcat(String1Var, varArgs...)
671
672 return cret
673}
674
675var xStrdelimit func(string, uintptr, byte) string
676
677// Converts any delimiter characters in @string to @new_delimiter.
678//
679// Any characters in @string which are found in @delimiters are
680// changed to the @new_delimiter character. Modifies @string in place,
681// and returns @string itself, not a copy.
682//
683// The return value is to allow nesting such as:
684// ```C
685// g_ascii_strup (g_strdelimit (str, "abc", '?'))
686// ```
687//
688// In order to modify a copy, you may use [func@GLib.strdup]:
689// ```C
690// reformatted = g_strdelimit (g_strdup (const_str), "abc", '?');
691// …
692// g_free (reformatted);
693// ```
694func Strdelimit(StringVar string, DelimitersVar *string, NewDelimiterVar byte) string {
695
696 DelimitersVarPtr := core.GStrdupNullable(DelimitersVar)
697 defer core.GFreeNullable(DelimitersVarPtr)
698
699 cret := xStrdelimit(StringVar, DelimitersVarPtr, NewDelimiterVar)
700
701 return cret
702}
703
704var xStrdown func(string) string
705
706// Converts a string to lower case.
707func Strdown(StringVar string) string {
708
709 cret := xStrdown(StringVar)
710
711 return cret
712}
713
714var xStrdup func(uintptr) string
715
716// Duplicates a string. If @str is `NULL` it returns `NULL`.
717func Strdup(StrVar *string) string {
718
719 StrVarPtr := core.GStrdupNullable(StrVar)
720 defer core.GFreeNullable(StrVarPtr)
721
722 cret := xStrdup(StrVarPtr)
723
724 return cret
725}
726
727var xStrdupPrintf func(string, ...interface{}) string
728
729// Similar to the standard C `sprintf()` function but safer, since it
730// calculates the maximum space required and allocates memory to hold
731// the result.
732//
733// The returned string is guaranteed to be non-NULL, unless @format
734// contains `%lc` or `%ls` conversions, which can fail if no multibyte
735// representation is available for the given character.
736func StrdupPrintf(FormatVar string, varArgs ...interface{}) string {
737
738 cret := xStrdupPrintf(FormatVar, varArgs...)
739
740 return cret
741}
742
743var xStrdupVprintf func(string, []interface{}) string
744
745// Similar to the standard C `vsprintf()` function but safer, since it
746// calculates the maximum space required and allocates memory to hold
747// the result.
748//
749// The returned string is guaranteed to be non-NULL, unless @format
750// contains `%lc` or `%ls` conversions, which can fail if no multibyte
751// representation is available for the given character.
752//
753// See also [func@GLib.vasprintf], which offers the same functionality, but
754// additionally returns the length of the allocated string.
755func StrdupVprintf(FormatVar string, ArgsVar []interface{}) string {
756
757 cret := xStrdupVprintf(FormatVar, ArgsVar)
758
759 return cret
760}
761
762var xStrdupv func([]string) []string
763
764// Copies an array of strings. The copy is a deep copy; each string is also
765// copied.
766//
767// If called on a `NULL` value, `g_strdupv()` simply returns `NULL`.
768func Strdupv(StrArrayVar []string) []string {
769
770 cret := xStrdupv(StrArrayVar)
771
772 return cret
773}
774
775var xStrerror func(int) string
776
777// Returns a string corresponding to the given error code, e.g. "no
778// such process".
779//
780// Unlike `strerror()`, this always returns a string in
781// UTF-8 encoding, and the pointer is guaranteed to remain valid for
782// the lifetime of the process. If the error code is unknown, it returns a
783// string like “Unknown error <code\>”.
784//
785// Note that the string may be translated according to the current locale.
786//
787// The value of `errno` will not be changed by this function. However, it may
788// be changed by intermediate function calls, so you should save its value
789// as soon as the call returns:
790// ```C
791// int saved_errno;
792//
793// ret = read (blah);
794// saved_errno = errno;
795//
796// g_strerror (saved_errno);
797// ```
798func Strerror(ErrnumVar int) string {
799
800 cret := xStrerror(ErrnumVar)
801
802 return cret
803}
804
805var xStrescape func(string, uintptr) string
806
807// It replaces the following special characters in the string @source
808// with their corresponding C escape sequence:
809//
810// | Symbol | Escape |
811// |-----------------------------------------------------------------------------|--------|
812// | [U+0008 Backspace](https://en.wikipedia.org/wiki/Backspace) | `\b` |
813// | [U+000C Form Feed](https://en.wikipedia.org/wiki/Form_feed) | `\f` |
814// | [U+000A Line Feed](https://en.wikipedia.org/wiki/Newline) | `\n` |
815// | [U+000D Carriage Return](https://en.wikipedia.org/wiki/Carriage_return) | `\r` |
816// | [U+0009 Horizontal Tabulation](https://en.wikipedia.org/wiki/Tab_character) | `\t` |
817// | [U+000B Vertical Tabulation](https://en.wikipedia.org/wiki/Vertical_Tab) | `\v` |
818//
819// It also inserts a backslash (`\`) before any backslash or a double quote (`"`).
820// Additionally all characters in the range 0x01-0x1F (everything
821// below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are
822// replaced with a backslash followed by their octal representation.
823// Characters supplied in @exceptions are not escaped.
824//
825// [func@GLib.strcompress] does the reverse conversion.
826func Strescape(SourceVar string, ExceptionsVar *string) string {
827
828 ExceptionsVarPtr := core.GStrdupNullable(ExceptionsVar)
829 defer core.GFreeNullable(ExceptionsVarPtr)
830
831 cret := xStrescape(SourceVar, ExceptionsVarPtr)
832
833 return cret
834}
835
836var xStrfreev func([]string)
837
838// Frees an array of strings, as well as each string it contains.
839//
840// If @str_array is `NULL`, this function simply returns.
841func Strfreev(StrArrayVar []string) {
842
843 xStrfreev(StrArrayVar)
844
845}
846
847var xStrjoin func(uintptr, ...interface{}) string
848
849// Joins a number of strings together to form one long string, with the
850// optional @separator inserted between each of them.
851func Strjoin(SeparatorVar *string, varArgs ...interface{}) string {
852
853 SeparatorVarPtr := core.GStrdupNullable(SeparatorVar)
854 defer core.GFreeNullable(SeparatorVarPtr)
855
856 cret := xStrjoin(SeparatorVarPtr, varArgs...)
857
858 return cret
859}
860
861var xStrjoinv func(uintptr, []string) string
862
863// Joins an array of strings together to form one long string, with the
864// optional @separator inserted between each of them.
865//
866// If @str_array has no items, the return value will be an
867// empty string. If @str_array contains a single item, @separator will not
868// appear in the resulting string.
869func Strjoinv(SeparatorVar *string, StrArrayVar []string) string {
870
871 SeparatorVarPtr := core.GStrdupNullable(SeparatorVar)
872 defer core.GFreeNullable(SeparatorVarPtr)
873
874 cret := xStrjoinv(SeparatorVarPtr, StrArrayVar)
875
876 return cret
877}
878
879var xStrlcat func(string, string, uint) uint
880
881// Portability wrapper that calls `strlcat()` on systems which have it,
882// and emulates it otherwise. Appends nul-terminated @src string to @dest,
883// guaranteeing nul-termination for @dest. The total size of @dest won't
884// exceed @dest_size.
885//
886// At most @dest_size - 1 characters will be copied. Unlike `strncat()`,
887// @dest_size is the full size of dest, not the space left over. This
888// function does not allocate memory. It always nul-terminates (unless
889// @dest_size == 0 or there were no nul characters in the @dest_size
890// characters of dest to start with).
891//
892// Caveat: this is supposedly a more secure alternative to `strcat()` or
893// `strncat()`, but for real security [func@GLib.strconcat] is harder to mess up.
894func Strlcat(DestVar string, SrcVar string, DestSizeVar uint) uint {
895
896 cret := xStrlcat(DestVar, SrcVar, DestSizeVar)
897
898 return cret
899}
900
901var xStrlcpy func(string, string, uint) uint
902
903// Portability wrapper that calls `strlcpy()` on systems which have it,
904// and emulates `strlcpy()` otherwise. Copies @src to @dest; @dest is
905// guaranteed to be nul-terminated; @src must be nul-terminated;
906// @dest_size is the buffer size, not the number of bytes to copy.
907//
908// At most @dest_size - 1 characters will be copied. Always nul-terminates
909// (unless @dest_size is 0). This function does not allocate memory. Unlike
910// `strncpy()`, this function doesn't pad @dest (so it's often faster). It
911// returns the size of the attempted result, `strlen (src)`, so if
912// @retval >= @dest_size, truncation occurred.
913//
914// Caveat: `strlcpy()` is supposedly more secure than `strcpy()` or `strncpy()`,
915// but if you really want to avoid screwups, [func@GLib.strdup] is an even better
916// idea.
917func Strlcpy(DestVar string, SrcVar string, DestSizeVar uint) uint {
918
919 cret := xStrlcpy(DestVar, SrcVar, DestSizeVar)
920
921 return cret
922}
923
924var xStrncasecmp func(string, string, uint) int
925
926// A case-insensitive string comparison, corresponding to the standard
927// `strncasecmp()` function on platforms which support it. It is similar
928// to [func@GLib.strcasecmp] except it only compares the first @n characters of
929// the strings.
930func Strncasecmp(S1Var string, S2Var string, NVar uint) int {
931
932 cret := xStrncasecmp(S1Var, S2Var, NVar)
933
934 return cret
935}
936
937var xStrndup func(uintptr, uint) string
938
939// Duplicates the first @n bytes of a string, returning a newly-allocated
940// buffer @n + 1 bytes long which will always be nul-terminated. If @str
941// is less than @n bytes long the buffer is padded with nuls. If @str is
942// `NULL` it returns `NULL`.
943//
944// To copy a number of characters from a UTF-8 encoded string,
945// use [func@GLib.utf8_strncpy] instead.
946func Strndup(StrVar *string, NVar uint) string {
947
948 StrVarPtr := core.GStrdupNullable(StrVar)
949 defer core.GFreeNullable(StrVarPtr)
950
951 cret := xStrndup(StrVarPtr, NVar)
952
953 return cret
954}
955
956var xStrnfill func(uint, byte) string
957
958// Creates a new string @length bytes long filled with @fill_char.
959func Strnfill(LengthVar uint, FillCharVar byte) string {
960
961 cret := xStrnfill(LengthVar, FillCharVar)
962
963 return cret
964}
965
966var xStrreverse func(string) string
967
968// Reverses all of the bytes in a string. For example,
969// `g_strreverse ("abcdef")` will result in "fedcba".
970//
971// Note that `g_strreverse()` doesn't work on UTF-8 strings
972// containing multibyte characters. For that purpose, use
973// [func@GLib.utf8_strreverse].
974func Strreverse(StringVar string) string {
975
976 cret := xStrreverse(StringVar)
977
978 return cret
979}
980
981var xStrrstr func(string, string) string
982
983// Searches the string @haystack for the last occurrence
984// of the string @needle.
985//
986// The fact that this function returns `gchar *` rather than `const gchar *` is
987// a historical artifact.
988func Strrstr(HaystackVar string, NeedleVar string) string {
989
990 cret := xStrrstr(HaystackVar, NeedleVar)
991
992 return cret
993}
994
995var xStrrstrLen func(string, int, string) string
996
997// Searches the string @haystack for the last occurrence
998// of the string @needle, limiting the length of the search
999// to @haystack_len.
1000//
1001// The fact that this function returns `gchar *` rather than `const gchar *` is
1002// a historical artifact.
1003func StrrstrLen(HaystackVar string, HaystackLenVar int, NeedleVar string) string {
1004
1005 cret := xStrrstrLen(HaystackVar, HaystackLenVar, NeedleVar)
1006
1007 return cret
1008}
1009
1010var xStrsignal func(int) string
1011
1012// Returns a string describing the given signal, e.g. "Segmentation fault".
1013// If the signal is unknown, it returns “unknown signal (<signum\>)”.
1014//
1015// You should use this function in preference to `strsignal()`, because it
1016// returns a string in UTF-8 encoding, and since not all platforms support
1017// the `strsignal()` function.
1018func Strsignal(SignumVar int) string {
1019
1020 cret := xStrsignal(SignumVar)
1021
1022 return cret
1023}
1024
1025var xStrsplit func(string, string, int) []string
1026
1027// Splits a string into a maximum of @max_tokens pieces, using the given
1028// @delimiter. If @max_tokens is reached, the remainder of @string is
1029// appended to the last token.
1030//
1031// As an example, the result of `g_strsplit (":a:bc::d:", ":", -1)` is an array
1032// containing the six strings "", "a", "bc", "", "d" and "".
1033//
1034// As a special case, the result of splitting the empty string "" is an empty
1035// array, not an array containing a single string. The reason for this
1036// special case is that being able to represent an empty array is typically
1037// more useful than consistent handling of empty elements. If you do need
1038// to represent empty elements, you'll need to check for the empty string
1039// before calling `g_strsplit()`.
1040func Strsplit(StringVar string, DelimiterVar string, MaxTokensVar int) []string {
1041
1042 cret := xStrsplit(StringVar, DelimiterVar, MaxTokensVar)
1043
1044 return cret
1045}
1046
1047var xStrsplitSet func(string, string, int) []string
1048
1049// Splits @string into a number of tokens not containing any of the characters
1050// in @delimiters. A token is the (possibly empty) longest string that does not
1051// contain any of the characters in @delimiters. If @max_tokens is reached, the
1052// remainder is appended to the last token.
1053//
1054// For example, the result of g_strsplit_set ("abc:def/ghi", ":/", -1) is an
1055// array containing the three strings "abc", "def", and "ghi".
1056//
1057// The result of g_strsplit_set (":def/ghi:", ":/", -1) is an array containing
1058// the four strings "", "def", "ghi", and "".
1059//
1060// As a special case, the result of splitting the empty string "" is an empty
1061// array, not an array containing a single string. The reason for this
1062// special case is that being able to represent an empty array is typically
1063// more useful than consistent handling of empty elements. If you do need
1064// to represent empty elements, you'll need to check for the empty string
1065// before calling `g_strsplit_set()`.
1066//
1067// Note that this function works on bytes not characters, so it can't be used
1068// to delimit UTF-8 strings for anything but ASCII characters.
1069func StrsplitSet(StringVar string, DelimitersVar string, MaxTokensVar int) []string {
1070
1071 cret := xStrsplitSet(StringVar, DelimitersVar, MaxTokensVar)
1072
1073 return cret
1074}
1075
1076var xStrstrLen func(string, int, string) string
1077
1078// Searches the string @haystack for the first occurrence
1079// of the string @needle, limiting the length of the search
1080// to @haystack_len or a nul terminator byte (whichever is reached first).
1081//
1082// A length of `-1` can be used to mean “search the entire string”, like
1083// `strstr()`.
1084//
1085// The fact that this function returns `gchar *` rather than `const gchar *` is
1086// a historical artifact.
1087func StrstrLen(HaystackVar string, HaystackLenVar int, NeedleVar string) string {
1088
1089 cret := xStrstrLen(HaystackVar, HaystackLenVar, NeedleVar)
1090
1091 return cret
1092}
1093
1094var xStrtod func(string, *string) float64
1095
1096// Converts a string to a floating point value.
1097//
1098// It calls the standard `strtod()` function to handle the conversion, but
1099// if the string is not completely converted it attempts the conversion
1100// again with [func@GLib.ascii_strtod], and returns the best match.
1101//
1102// This function should seldom be used. The normal situation when reading
1103// numbers not for human consumption is to use [func@GLib.ascii_strtod]. Only when
1104// you know that you must expect both locale formatted and C formatted numbers
1105// should you use this. Make sure that you don't pass strings such as comma
1106// separated lists of values, since the commas may be interpreted as a decimal
1107// point in some locales, causing unexpected results.
1108func Strtod(NptrVar string, EndptrVar *string) float64 {
1109
1110 cret := xStrtod(NptrVar, EndptrVar)
1111
1112 return cret
1113}
1114
1115var xStrup func(string) string
1116
1117// Converts a string to upper case.
1118func Strup(StringVar string) string {
1119
1120 cret := xStrup(StringVar)
1121
1122 return cret
1123}
1124
1125var xStrvContains func([]string, string) bool
1126
1127// Checks if an array of strings contains the string @str according to
1128// [func@GLib.str_equal]. @strv must not be `NULL`.
1129func StrvContains(StrvVar []string, StrVar string) bool {
1130
1131 cret := xStrvContains(StrvVar, StrVar)
1132
1133 return cret
1134}
1135
1136var xStrvEqual func([]string, []string) bool
1137
1138// Checks if two arrays of strings contain exactly the same elements in
1139// exactly the same order.
1140//
1141// Elements are compared using [func@GLib.str_equal]. To match independently
1142// of order, sort the arrays first (using [func@GLib.qsort_with_data]
1143// or similar).
1144//
1145// Two empty arrays are considered equal. Neither @strv1 nor @strv2 may be
1146// `NULL`.
1147func StrvEqual(Strv1Var []string, Strv2Var []string) bool {
1148
1149 cret := xStrvEqual(Strv1Var, Strv2Var)
1150
1151 return cret
1152}
1153
1154var xStrvLength func([]string) uint
1155
1156// Returns the length of an array of strings. @str_array must not be `NULL`.
1157func StrvLength(StrArrayVar []string) uint {
1158
1159 cret := xStrvLength(StrArrayVar)
1160
1161 return cret
1162}
1163
1164func init() {
1165 core.SetPackageName("GLIB", "glib-2.0")
1166 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
1167 var libs []uintptr
1168 for _, libPath := range core.GetPaths("GLIB") {
1169 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
1170 if err != nil {
1171 panic(err)
1172 }
1173 libs = append(libs, lib)
1174 }
1175
1176 core.PuregoSafeRegister(&xAsciiDigitValue, libs, "g_ascii_digit_value")
1177 core.PuregoSafeRegister(&xAsciiDtostr, libs, "g_ascii_dtostr")
1178 core.PuregoSafeRegister(&xAsciiFormatd, libs, "g_ascii_formatd")
1179 core.PuregoSafeRegister(&xAsciiStrcasecmp, libs, "g_ascii_strcasecmp")
1180 core.PuregoSafeRegister(&xAsciiStrdown, libs, "g_ascii_strdown")
1181 core.PuregoSafeRegister(&xAsciiStringToSigned, libs, "g_ascii_string_to_signed")
1182 core.PuregoSafeRegister(&xAsciiStringToUnsigned, libs, "g_ascii_string_to_unsigned")
1183 core.PuregoSafeRegister(&xAsciiStrncasecmp, libs, "g_ascii_strncasecmp")
1184 core.PuregoSafeRegister(&xAsciiStrtod, libs, "g_ascii_strtod")
1185 core.PuregoSafeRegister(&xAsciiStrtoll, libs, "g_ascii_strtoll")
1186 core.PuregoSafeRegister(&xAsciiStrtoull, libs, "g_ascii_strtoull")
1187 core.PuregoSafeRegister(&xAsciiStrup, libs, "g_ascii_strup")
1188 core.PuregoSafeRegister(&xAsciiTolower, libs, "g_ascii_tolower")
1189 core.PuregoSafeRegister(&xAsciiToupper, libs, "g_ascii_toupper")
1190 core.PuregoSafeRegister(&xAsciiXdigitValue, libs, "g_ascii_xdigit_value")
1191 core.PuregoSafeRegister(&xMemdup, libs, "g_memdup")
1192 core.PuregoSafeRegister(&xMemdup2, libs, "g_memdup2")
1193 core.PuregoSafeRegister(&xStpcpy, libs, "g_stpcpy")
1194 core.PuregoSafeRegister(&xStrHasPrefix, libs, "g_str_has_prefix")
1195 core.PuregoSafeRegister(&xStrHasSuffix, libs, "g_str_has_suffix")
1196 core.PuregoSafeRegister(&xStrIsAscii, libs, "g_str_is_ascii")
1197 core.PuregoSafeRegister(&xStrMatchString, libs, "g_str_match_string")
1198 core.PuregoSafeRegister(&xStrToAscii, libs, "g_str_to_ascii")
1199 core.PuregoSafeRegister(&xStrTokenizeAndFold, libs, "g_str_tokenize_and_fold")
1200 core.PuregoSafeRegister(&xStrcanon, libs, "g_strcanon")
1201 core.PuregoSafeRegister(&xStrcasecmp, libs, "g_strcasecmp")
1202 core.PuregoSafeRegister(&xStrchomp, libs, "g_strchomp")
1203 core.PuregoSafeRegister(&xStrchug, libs, "g_strchug")
1204 core.PuregoSafeRegister(&xStrcompress, libs, "g_strcompress")
1205 core.PuregoSafeRegister(&xStrconcat, libs, "g_strconcat")
1206 core.PuregoSafeRegister(&xStrdelimit, libs, "g_strdelimit")
1207 core.PuregoSafeRegister(&xStrdown, libs, "g_strdown")
1208 core.PuregoSafeRegister(&xStrdup, libs, "g_strdup")
1209 core.PuregoSafeRegister(&xStrdupPrintf, libs, "g_strdup_printf")
1210 core.PuregoSafeRegister(&xStrdupVprintf, libs, "g_strdup_vprintf")
1211 core.PuregoSafeRegister(&xStrdupv, libs, "g_strdupv")
1212 core.PuregoSafeRegister(&xStrerror, libs, "g_strerror")
1213 core.PuregoSafeRegister(&xStrescape, libs, "g_strescape")
1214 core.PuregoSafeRegister(&xStrfreev, libs, "g_strfreev")
1215 core.PuregoSafeRegister(&xStrjoin, libs, "g_strjoin")
1216 core.PuregoSafeRegister(&xStrjoinv, libs, "g_strjoinv")
1217 core.PuregoSafeRegister(&xStrlcat, libs, "g_strlcat")
1218 core.PuregoSafeRegister(&xStrlcpy, libs, "g_strlcpy")
1219 core.PuregoSafeRegister(&xStrncasecmp, libs, "g_strncasecmp")
1220 core.PuregoSafeRegister(&xStrndup, libs, "g_strndup")
1221 core.PuregoSafeRegister(&xStrnfill, libs, "g_strnfill")
1222 core.PuregoSafeRegister(&xStrreverse, libs, "g_strreverse")
1223 core.PuregoSafeRegister(&xStrrstr, libs, "g_strrstr")
1224 core.PuregoSafeRegister(&xStrrstrLen, libs, "g_strrstr_len")
1225 core.PuregoSafeRegister(&xStrsignal, libs, "g_strsignal")
1226 core.PuregoSafeRegister(&xStrsplit, libs, "g_strsplit")
1227 core.PuregoSafeRegister(&xStrsplitSet, libs, "g_strsplit_set")
1228 core.PuregoSafeRegister(&xStrstrLen, libs, "g_strstr_len")
1229 core.PuregoSafeRegister(&xStrtod, libs, "g_strtod")
1230 core.PuregoSafeRegister(&xStrup, libs, "g_strup")
1231 core.PuregoSafeRegister(&xStrvContains, libs, "g_strv_contains")
1232 core.PuregoSafeRegister(&xStrvEqual, libs, "g_strv_equal")
1233 core.PuregoSafeRegister(&xStrvLength, libs, "g_strv_length")
1234
1235}