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.Str;
26 
27 private import core.stdc.stdio;
28 private import core.stdc.string;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.Str;
32 private import glib.c.functions;
33 public  import glib.c.types;
34 public  import gobject.c.types;
35 public  import gtkc.glibtypes;
36 
37 
38 /** */
39 public struct Str
40 {
41 	/*
42 	 * Convert C-style 0 terminated string s to char[] string.
43 	 * copied from phobos
44 	 */
45 	public static string toString(const(char)* s, size_t len = 0) pure
46 	{
47 		if ( s is null )
48 			return cast(string)null;
49 
50 		if ( len == 0 )
51 			len = strlen(s);
52 
53 		return s[0 .. len].idup;
54 	}
55 
56 	/*
57 	 * Convert array of chars s[] to a C-style 0 terminated string.
58 	 * copied from phobos
59 	 */
60 	public static char* toStringz(string s) pure
61 	{
62 		if ( s is null ) return null;
63 		char[] copy;
64 
65 		if (s.length == 0)
66 		{
67 			copy = "\0".dup;
68 		}
69 		else
70 		{
71 			// Need to make a copy
72 			copy = new char[s.length + 1];
73 			copy[0..s.length] = s[];
74 			copy[s.length] = 0;
75 		}
76 
77 		return copy.ptr;
78 	}
79 
80 	/** */
81 	public static char** toStringzArray(string[] args) pure
82 	{
83 		if ( args is null )
84 		{
85 			return null;
86 		}
87 		char** argv = (new char*[args.length + 1]).ptr;
88 		int argc = 0;
89 		foreach (string p; args)
90 		{
91 			argv[argc++] = cast(char*)(p.dup~'\0');
92 		}
93 		argv[argc] = null;
94 
95 		return argv;
96 	}
97 
98 	/** */
99 	public static char*** toStringzArray(string[][] args) pure
100 	{
101 		if ( args is null )
102 		{
103 			return null;
104 		}
105 		char**[] argv = new char**[args.length + 1];
106 		int argc = 0;
107 		foreach( string[] p; args )
108 		{
109 			argv[argc++] = toStringzArray(p);
110 		}
111 		argv[argc] = null;
112 
113 		return argv.ptr;
114 	}
115 
116 	/** */
117 	public static string[] toStringArray(const(char*)* args) pure
118 	{
119 		if ( args is null )
120 		{
121 			return null;
122 		}
123 		string[] argv;
124 
125 		while ( *args !is null )
126 		{
127 			argv ~= toString(*args);
128 			args++;
129 		}
130 
131 		return argv;
132 	}
133 
134 	/** */
135 	public static string[] toStringArray(const(char*)* args, size_t len) pure
136 	{
137 		string[] argv = new string[len];
138 
139 		for ( int i; i < len; i++ )
140 		{
141 			argv[i] = toString(args[i]);
142 		}
143 
144 		return argv;
145 	}
146 
147 	/** */
148 	public static string[][] toStringArray(char*** args) pure
149 	{
150 		string[][] argv;
151 
152 		if ( args is null )
153 		{
154 			return null;
155 		}
156 
157 		while ( *args !is null )
158 		{
159 			argv ~= toStringArray(*args);
160 			args++;
161 		}
162 
163 		return argv;
164 	}
165 
166 	/** */
167 	public static void freeString(char* str)
168 	{
169 		g_free(str);
170 	}
171 
172 	/** */
173 	public static void freeStringArray(char** str)
174 	{
175 		g_strfreev(str);
176 	}
177 
178 	/** */
179 	public static void freeStringArray(char*** str)
180 	{
181 		while ( *str !is null )
182 		{
183 			g_strfreev(*str);
184 			str++;
185 		}
186 
187 		g_free(str);
188 	}
189 
190 	/**
191 	 */
192 
193 	/**
194 	 * Determines the numeric value of a character as a decimal digit.
195 	 * Differs from g_unichar_digit_value() because it takes a char, so
196 	 * there's no worry about sign extension if characters are signed.
197 	 *
198 	 * Params:
199 	 *     c = an ASCII character
200 	 *
201 	 * Returns: If @c is a decimal digit (according to g_ascii_isdigit()),
202 	 *     its numeric value. Otherwise, -1.
203 	 */
204 	public static int asciiDigitValue(char c)
205 	{
206 		return g_ascii_digit_value(c);
207 	}
208 
209 	/**
210 	 * Converts a #gdouble to a string, using the '.' as
211 	 * decimal point.
212 	 *
213 	 * This function generates enough precision that converting
214 	 * the string back using g_ascii_strtod() gives the same machine-number
215 	 * (on machines with IEEE compatible 64bit doubles). It is
216 	 * guaranteed that the size of the resulting string will never
217 	 * be larger than @G_ASCII_DTOSTR_BUF_SIZE bytes, including the terminating
218 	 * nul character, which is always added.
219 	 *
220 	 * Params:
221 	 *     buffer = A buffer to place the resulting string in
222 	 *     bufLen = The length of the buffer.
223 	 *     d = The #gdouble to convert
224 	 *
225 	 * Returns: The pointer to the buffer with the converted string.
226 	 */
227 	public static string asciiDtostr(string buffer, int bufLen, double d)
228 	{
229 		auto retStr = g_ascii_dtostr(Str.toStringz(buffer), bufLen, d);
230 
231 		scope(exit) Str.freeString(retStr);
232 		return Str.toString(retStr);
233 	}
234 
235 	/**
236 	 * Converts a #gdouble to a string, using the '.' as
237 	 * decimal point. To format the number you pass in
238 	 * a printf()-style format string. Allowed conversion
239 	 * specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'.
240 	 *
241 	 * The returned buffer is guaranteed to be nul-terminated.
242 	 *
243 	 * If you just want to want to serialize the value into a
244 	 * string, use g_ascii_dtostr().
245 	 *
246 	 * Params:
247 	 *     buffer = A buffer to place the resulting string in
248 	 *     bufLen = The length of the buffer.
249 	 *     format = The printf()-style format to use for the
250 	 *         code to use for converting.
251 	 *     d = The #gdouble to convert
252 	 *
253 	 * Returns: The pointer to the buffer with the converted string.
254 	 */
255 	public static string asciiFormatd(string buffer, int bufLen, string format, double d)
256 	{
257 		auto retStr = g_ascii_formatd(Str.toStringz(buffer), bufLen, Str.toStringz(format), d);
258 
259 		scope(exit) Str.freeString(retStr);
260 		return Str.toString(retStr);
261 	}
262 
263 	/**
264 	 * Compare two strings, ignoring the case of ASCII characters.
265 	 *
266 	 * Unlike the BSD strcasecmp() function, this only recognizes standard
267 	 * ASCII letters and ignores the locale, treating all non-ASCII
268 	 * bytes as if they are not letters.
269 	 *
270 	 * This function should be used only on strings that are known to be
271 	 * in encodings where the bytes corresponding to ASCII letters always
272 	 * represent themselves. This includes UTF-8 and the ISO-8859-*
273 	 * charsets, but not for instance double-byte encodings like the
274 	 * Windows Codepage 932, where the trailing bytes of double-byte
275 	 * characters include all ASCII letters. If you compare two CP932
276 	 * strings using this function, you will get false matches.
277 	 *
278 	 * Both @s1 and @s2 must be non-%NULL.
279 	 *
280 	 * Params:
281 	 *     s1 = string to compare with @s2
282 	 *     s2 = string to compare with @s1
283 	 *
284 	 * Returns: 0 if the strings match, a negative value if @s1 < @s2,
285 	 *     or a positive value if @s1 > @s2.
286 	 */
287 	public static int asciiStrcasecmp(string s1, string s2)
288 	{
289 		return g_ascii_strcasecmp(Str.toStringz(s1), Str.toStringz(s2));
290 	}
291 
292 	/**
293 	 * Converts all upper case ASCII letters to lower case ASCII letters.
294 	 *
295 	 * Params:
296 	 *     str = a string
297 	 *     len = length of @str in bytes, or -1 if @str is nul-terminated
298 	 *
299 	 * Returns: a newly-allocated string, with all the upper case
300 	 *     characters in @str converted to lower case, with semantics that
301 	 *     exactly match g_ascii_tolower(). (Note that this is unlike the
302 	 *     old g_strdown(), which modified the string in place.)
303 	 */
304 	public static string asciiStrdown(string str, ptrdiff_t len)
305 	{
306 		auto retStr = g_ascii_strdown(Str.toStringz(str), len);
307 
308 		scope(exit) Str.freeString(retStr);
309 		return Str.toString(retStr);
310 	}
311 
312 	/**
313 	 * Compare @s1 and @s2, ignoring the case of ASCII characters and any
314 	 * characters after the first @n in each string.
315 	 *
316 	 * Unlike the BSD strcasecmp() function, this only recognizes standard
317 	 * ASCII letters and ignores the locale, treating all non-ASCII
318 	 * characters as if they are not letters.
319 	 *
320 	 * The same warning as in g_ascii_strcasecmp() applies: Use this
321 	 * function only on strings known to be in encodings where bytes
322 	 * corresponding to ASCII letters always represent themselves.
323 	 *
324 	 * Params:
325 	 *     s1 = string to compare with @s2
326 	 *     s2 = string to compare with @s1
327 	 *     n = number of characters to compare
328 	 *
329 	 * Returns: 0 if the strings match, a negative value if @s1 < @s2,
330 	 *     or a positive value if @s1 > @s2.
331 	 */
332 	public static int asciiStrncasecmp(string s1, string s2, size_t n)
333 	{
334 		return g_ascii_strncasecmp(Str.toStringz(s1), Str.toStringz(s2), n);
335 	}
336 
337 	/**
338 	 * Converts a string to a #gdouble value.
339 	 *
340 	 * This function behaves like the standard strtod() function
341 	 * does in the C locale. It does this without actually changing
342 	 * the current locale, since that would not be thread-safe.
343 	 * A limitation of the implementation is that this function
344 	 * will still accept localized versions of infinities and NANs.
345 	 *
346 	 * This function is typically used when reading configuration
347 	 * files or other non-user input that should be locale independent.
348 	 * To handle input from the user you should normally use the
349 	 * locale-sensitive system strtod() function.
350 	 *
351 	 * To convert from a #gdouble to a string in a locale-insensitive
352 	 * way, use g_ascii_dtostr().
353 	 *
354 	 * If the correct value would cause overflow, plus or minus %HUGE_VAL
355 	 * is returned (according to the sign of the value), and %ERANGE is
356 	 * stored in %errno. If the correct value would cause underflow,
357 	 * zero is returned and %ERANGE is stored in %errno.
358 	 *
359 	 * This function resets %errno before calling strtod() so that
360 	 * you can reliably detect overflow and underflow.
361 	 *
362 	 * Params:
363 	 *     nptr = the string to convert to a numeric value.
364 	 *     endptr = if non-%NULL, it returns the
365 	 *         character after the last character used in the conversion.
366 	 *
367 	 * Returns: the #gdouble value.
368 	 */
369 	public static double asciiStrtod(string nptr, out string endptr)
370 	{
371 		char* outendptr = null;
372 
373 		auto __p = g_ascii_strtod(Str.toStringz(nptr), &outendptr);
374 
375 		endptr = Str.toString(outendptr);
376 
377 		return __p;
378 	}
379 
380 	/**
381 	 * Converts a string to a #gint64 value.
382 	 * This function behaves like the standard strtoll() function
383 	 * does in the C locale. It does this without actually
384 	 * changing the current locale, since that would not be
385 	 * thread-safe.
386 	 *
387 	 * This function is typically used when reading configuration
388 	 * files or other non-user input that should be locale independent.
389 	 * To handle input from the user you should normally use the
390 	 * locale-sensitive system strtoll() function.
391 	 *
392 	 * If the correct value would cause overflow, %G_MAXINT64 or %G_MININT64
393 	 * is returned, and `ERANGE` is stored in `errno`.
394 	 * If the base is outside the valid range, zero is returned, and
395 	 * `EINVAL` is stored in `errno`. If the
396 	 * string conversion fails, zero is returned, and @endptr returns @nptr
397 	 * (if @endptr is non-%NULL).
398 	 *
399 	 * Params:
400 	 *     nptr = the string to convert to a numeric value.
401 	 *     endptr = if non-%NULL, it returns the
402 	 *         character after the last character used in the conversion.
403 	 *     base = to be used for the conversion, 2..36 or 0
404 	 *
405 	 * Returns: the #gint64 value or zero on error.
406 	 *
407 	 * Since: 2.12
408 	 */
409 	public static long asciiStrtoll(string nptr, out string endptr, uint base)
410 	{
411 		char* outendptr = null;
412 
413 		auto __p = g_ascii_strtoll(Str.toStringz(nptr), &outendptr, base);
414 
415 		endptr = Str.toString(outendptr);
416 
417 		return __p;
418 	}
419 
420 	/**
421 	 * Converts a string to a #guint64 value.
422 	 * This function behaves like the standard strtoull() function
423 	 * does in the C locale. It does this without actually
424 	 * changing the current locale, since that would not be
425 	 * thread-safe.
426 	 *
427 	 * Note that input with a leading minus sign (`-`) is accepted, and will return
428 	 * the negation of the parsed number, unless that would overflow a #guint64.
429 	 * Critically, this means you cannot assume that a short fixed length input will
430 	 * never result in a low return value, as the input could have a leading `-`.
431 	 *
432 	 * This function is typically used when reading configuration
433 	 * files or other non-user input that should be locale independent.
434 	 * To handle input from the user you should normally use the
435 	 * locale-sensitive system strtoull() function.
436 	 *
437 	 * If the correct value would cause overflow, %G_MAXUINT64
438 	 * is returned, and `ERANGE` is stored in `errno`.
439 	 * If the base is outside the valid range, zero is returned, and
440 	 * `EINVAL` is stored in `errno`.
441 	 * If the string conversion fails, zero is returned, and @endptr returns
442 	 * @nptr (if @endptr is non-%NULL).
443 	 *
444 	 * Params:
445 	 *     nptr = the string to convert to a numeric value.
446 	 *     endptr = if non-%NULL, it returns the
447 	 *         character after the last character used in the conversion.
448 	 *     base = to be used for the conversion, 2..36 or 0
449 	 *
450 	 * Returns: the #guint64 value or zero on error.
451 	 *
452 	 * Since: 2.2
453 	 */
454 	public static ulong asciiStrtoull(string nptr, out string endptr, uint base)
455 	{
456 		char* outendptr = null;
457 
458 		auto __p = g_ascii_strtoull(Str.toStringz(nptr), &outendptr, base);
459 
460 		endptr = Str.toString(outendptr);
461 
462 		return __p;
463 	}
464 
465 	/**
466 	 * Converts all lower case ASCII letters to upper case ASCII letters.
467 	 *
468 	 * Params:
469 	 *     str = a string
470 	 *     len = length of @str in bytes, or -1 if @str is nul-terminated
471 	 *
472 	 * Returns: a newly allocated string, with all the lower case
473 	 *     characters in @str converted to upper case, with semantics that
474 	 *     exactly match g_ascii_toupper(). (Note that this is unlike the
475 	 *     old g_strup(), which modified the string in place.)
476 	 */
477 	public static string asciiStrup(string str, ptrdiff_t len)
478 	{
479 		auto retStr = g_ascii_strup(Str.toStringz(str), len);
480 
481 		scope(exit) Str.freeString(retStr);
482 		return Str.toString(retStr);
483 	}
484 
485 	/**
486 	 * Convert a character to ASCII lower case.
487 	 *
488 	 * Unlike the standard C library tolower() function, this only
489 	 * recognizes standard ASCII letters and ignores the locale, returning
490 	 * all non-ASCII characters unchanged, even if they are lower case
491 	 * letters in a particular character set. Also unlike the standard
492 	 * library function, this takes and returns a char, not an int, so
493 	 * don't call it on %EOF but no need to worry about casting to #guchar
494 	 * before passing a possibly non-ASCII character in.
495 	 *
496 	 * Params:
497 	 *     c = any character
498 	 *
499 	 * Returns: the result of converting @c to lower case. If @c is
500 	 *     not an ASCII upper case letter, @c is returned unchanged.
501 	 */
502 	public static char asciiTolower(char c)
503 	{
504 		return g_ascii_tolower(c);
505 	}
506 
507 	/**
508 	 * Convert a character to ASCII upper case.
509 	 *
510 	 * Unlike the standard C library toupper() function, this only
511 	 * recognizes standard ASCII letters and ignores the locale, returning
512 	 * all non-ASCII characters unchanged, even if they are upper case
513 	 * letters in a particular character set. Also unlike the standard
514 	 * library function, this takes and returns a char, not an int, so
515 	 * don't call it on %EOF but no need to worry about casting to #guchar
516 	 * before passing a possibly non-ASCII character in.
517 	 *
518 	 * Params:
519 	 *     c = any character
520 	 *
521 	 * Returns: the result of converting @c to upper case. If @c is not
522 	 *     an ASCII lower case letter, @c is returned unchanged.
523 	 */
524 	public static char asciiToupper(char c)
525 	{
526 		return g_ascii_toupper(c);
527 	}
528 
529 	/**
530 	 * Determines the numeric value of a character as a hexidecimal
531 	 * digit. Differs from g_unichar_xdigit_value() because it takes
532 	 * a char, so there's no worry about sign extension if characters
533 	 * are signed.
534 	 *
535 	 * Params:
536 	 *     c = an ASCII character.
537 	 *
538 	 * Returns: If @c is a hex digit (according to g_ascii_isxdigit()),
539 	 *     its numeric value. Otherwise, -1.
540 	 */
541 	public static int asciiXdigitValue(char c)
542 	{
543 		return g_ascii_xdigit_value(c);
544 	}
545 
546 	/**
547 	 * Calculates the maximum space needed to store the output
548 	 * of the sprintf() function.
549 	 *
550 	 * Params:
551 	 *     format = the format string. See the printf() documentation
552 	 *     args = the parameters to be inserted into the format string
553 	 *
554 	 * Returns: the maximum space needed to store the formatted string
555 	 */
556 	public static size_t printfStringUpperBound(string format, void* args)
557 	{
558 		return g_printf_string_upper_bound(Str.toStringz(format), args);
559 	}
560 
561 	/**
562 	 * Copies a nul-terminated string into the dest buffer, include the
563 	 * trailing nul, and return a pointer to the trailing nul byte.
564 	 * This is useful for concatenating multiple strings together
565 	 * without having to repeatedly scan for the end.
566 	 *
567 	 * Params:
568 	 *     dest = destination buffer.
569 	 *     src = source string.
570 	 *
571 	 * Returns: a pointer to trailing nul byte.
572 	 */
573 	public static string stpcpy(string dest, string src)
574 	{
575 		auto retStr = g_stpcpy(Str.toStringz(dest), Str.toStringz(src));
576 
577 		scope(exit) Str.freeString(retStr);
578 		return Str.toString(retStr);
579 	}
580 
581 	/**
582 	 * Looks whether the string @str begins with @prefix.
583 	 *
584 	 * Params:
585 	 *     str = a nul-terminated string
586 	 *     prefix = the nul-terminated prefix to look for
587 	 *
588 	 * Returns: %TRUE if @str begins with @prefix, %FALSE otherwise.
589 	 *
590 	 * Since: 2.2
591 	 */
592 	public static bool hasPrefix(string str, string prefix)
593 	{
594 		return g_str_has_prefix(Str.toStringz(str), Str.toStringz(prefix)) != 0;
595 	}
596 
597 	/**
598 	 * Looks whether the string @str ends with @suffix.
599 	 *
600 	 * Params:
601 	 *     str = a nul-terminated string
602 	 *     suffix = the nul-terminated suffix to look for
603 	 *
604 	 * Returns: %TRUE if @str end with @suffix, %FALSE otherwise.
605 	 *
606 	 * Since: 2.2
607 	 */
608 	public static bool hasSuffix(string str, string suffix)
609 	{
610 		return g_str_has_suffix(Str.toStringz(str), Str.toStringz(suffix)) != 0;
611 	}
612 
613 	/**
614 	 * Determines if a string is pure ASCII. A string is pure ASCII if it
615 	 * contains no bytes with the high bit set.
616 	 *
617 	 * Params:
618 	 *     str = a string
619 	 *
620 	 * Returns: %TRUE if @str is ASCII
621 	 *
622 	 * Since: 2.40
623 	 */
624 	public static bool isAscii(string str)
625 	{
626 		return g_str_is_ascii(Str.toStringz(str)) != 0;
627 	}
628 
629 	/**
630 	 * Checks if a search conducted for @search_term should match
631 	 * @potential_hit.
632 	 *
633 	 * This function calls g_str_tokenize_and_fold() on both
634 	 * @search_term and @potential_hit.  ASCII alternates are never taken
635 	 * for @search_term but will be taken for @potential_hit according to
636 	 * the value of @accept_alternates.
637 	 *
638 	 * A hit occurs when each folded token in @search_term is a prefix of a
639 	 * folded token from @potential_hit.
640 	 *
641 	 * Depending on how you're performing the search, it will typically be
642 	 * faster to call g_str_tokenize_and_fold() on each string in
643 	 * your corpus and build an index on the returned folded tokens, then
644 	 * call g_str_tokenize_and_fold() on the search term and
645 	 * perform lookups into that index.
646 	 *
647 	 * As some examples, searching for ‘fred’ would match the potential hit
648 	 * ‘Smith, Fred’ and also ‘Frédéric’.  Searching for ‘Fréd’ would match
649 	 * ‘Frédéric’ but not ‘Frederic’ (due to the one-directional nature of
650 	 * accent matching).  Searching ‘fo’ would match ‘Foo’ and ‘Bar Foo
651 	 * Baz’, but not ‘SFO’ (because no word has ‘fo’ as a prefix).
652 	 *
653 	 * Params:
654 	 *     searchTerm = the search term from the user
655 	 *     potentialHit = the text that may be a hit
656 	 *     acceptAlternates = %TRUE to accept ASCII alternates
657 	 *
658 	 * Returns: %TRUE if @potential_hit is a hit
659 	 *
660 	 * Since: 2.40
661 	 */
662 	public static bool matchString(string searchTerm, string potentialHit, bool acceptAlternates)
663 	{
664 		return g_str_match_string(Str.toStringz(searchTerm), Str.toStringz(potentialHit), acceptAlternates) != 0;
665 	}
666 
667 	/**
668 	 * Transliterate @str to plain ASCII.
669 	 *
670 	 * For best results, @str should be in composed normalised form.
671 	 *
672 	 * This function performs a reasonably good set of character
673 	 * replacements.  The particular set of replacements that is done may
674 	 * change by version or even by runtime environment.
675 	 *
676 	 * If the source language of @str is known, it can used to improve the
677 	 * accuracy of the translation by passing it as @from_locale.  It should
678 	 * be a valid POSIX locale string (of the form
679 	 * `language[_territory][.codeset][@modifier]`).
680 	 *
681 	 * If @from_locale is %NULL then the current locale is used.
682 	 *
683 	 * If you want to do translation for no specific locale, and you want it
684 	 * to be done independently of the currently locale, specify `"C"` for
685 	 * @from_locale.
686 	 *
687 	 * Params:
688 	 *     str = a string, in UTF-8
689 	 *     fromLocale = the source locale, if known
690 	 *
691 	 * Returns: a string in plain ASCII
692 	 *
693 	 * Since: 2.40
694 	 */
695 	public static string toAscii(string str, string fromLocale)
696 	{
697 		auto retStr = g_str_to_ascii(Str.toStringz(str), Str.toStringz(fromLocale));
698 
699 		scope(exit) Str.freeString(retStr);
700 		return Str.toString(retStr);
701 	}
702 
703 	/**
704 	 * Tokenises @string and performs folding on each token.
705 	 *
706 	 * A token is a non-empty sequence of alphanumeric characters in the
707 	 * source string, separated by non-alphanumeric characters.  An
708 	 * "alphanumeric" character for this purpose is one that matches
709 	 * g_unichar_isalnum() or g_unichar_ismark().
710 	 *
711 	 * Each token is then (Unicode) normalised and case-folded.  If
712 	 * @ascii_alternates is non-%NULL and some of the returned tokens
713 	 * contain non-ASCII characters, ASCII alternatives will be generated.
714 	 *
715 	 * The number of ASCII alternatives that are generated and the method
716 	 * for doing so is unspecified, but @translit_locale (if specified) may
717 	 * improve the transliteration if the language of the source string is
718 	 * known.
719 	 *
720 	 * Params:
721 	 *     string_ = a string
722 	 *     translitLocale = the language code (like 'de' or
723 	 *         'en_GB') from which @string originates
724 	 *     asciiAlternates = a
725 	 *         return location for ASCII alternates
726 	 *
727 	 * Returns: the folded tokens
728 	 *
729 	 * Since: 2.40
730 	 */
731 	public static string[] tokenizeAndFold(string string_, string translitLocale, out string[] asciiAlternates)
732 	{
733 		char** outasciiAlternates = null;
734 
735 		auto retStr = g_str_tokenize_and_fold(Str.toStringz(string_), Str.toStringz(translitLocale), &outasciiAlternates);
736 
737 		asciiAlternates = Str.toStringArray(outasciiAlternates);
738 
739 		scope(exit) Str.freeStringArray(retStr);
740 		return Str.toStringArray(retStr);
741 	}
742 
743 	/**
744 	 * For each character in @string, if the character is not in @valid_chars,
745 	 * replaces the character with @substitutor. Modifies @string in place,
746 	 * and return @string itself, not a copy. The return value is to allow
747 	 * nesting such as
748 	 * |[<!-- language="C" -->
749 	 * g_ascii_strup (g_strcanon (str, "abc", '?'))
750 	 * ]|
751 	 *
752 	 * In order to modify a copy, you may use `g_strdup()`:
753 	 * |[<!-- language="C" -->
754 	 * reformatted = g_strcanon (g_strdup (const_str), "abc", '?');
755 	 * ...
756 	 * g_free (reformatted);
757 	 * ]|
758 	 *
759 	 * Params:
760 	 *     string_ = a nul-terminated array of bytes
761 	 *     validChars = bytes permitted in @string
762 	 *     substitutor = replacement character for disallowed bytes
763 	 *
764 	 * Returns: @string
765 	 */
766 	public static string strcanon(string string_, string validChars, char substitutor)
767 	{
768 		auto retStr = g_strcanon(Str.toStringz(string_), Str.toStringz(validChars), substitutor);
769 
770 		scope(exit) Str.freeString(retStr);
771 		return Str.toString(retStr);
772 	}
773 
774 	/**
775 	 * A case-insensitive string comparison, corresponding to the standard
776 	 * strcasecmp() function on platforms which support it.
777 	 *
778 	 * Deprecated: See g_strncasecmp() for a discussion of why this
779 	 * function is deprecated and how to replace it.
780 	 *
781 	 * Params:
782 	 *     s1 = a string
783 	 *     s2 = a string to compare with @s1
784 	 *
785 	 * Returns: 0 if the strings match, a negative value if @s1 < @s2,
786 	 *     or a positive value if @s1 > @s2.
787 	 */
788 	public static int strcasecmp(string s1, string s2)
789 	{
790 		return g_strcasecmp(Str.toStringz(s1), Str.toStringz(s2));
791 	}
792 
793 	/**
794 	 * Removes trailing whitespace from a string.
795 	 *
796 	 * This function doesn't allocate or reallocate any memory;
797 	 * it modifies @string in place. Therefore, it cannot be used
798 	 * on statically allocated strings.
799 	 *
800 	 * The pointer to @string is returned to allow the nesting of functions.
801 	 *
802 	 * Also see g_strchug() and g_strstrip().
803 	 *
804 	 * Params:
805 	 *     string_ = a string to remove the trailing whitespace from
806 	 *
807 	 * Returns: @string
808 	 */
809 	public static string strchomp(string string_)
810 	{
811 		auto retStr = g_strchomp(Str.toStringz(string_));
812 
813 		scope(exit) Str.freeString(retStr);
814 		return Str.toString(retStr);
815 	}
816 
817 	/**
818 	 * Removes leading whitespace from a string, by moving the rest
819 	 * of the characters forward.
820 	 *
821 	 * This function doesn't allocate or reallocate any memory;
822 	 * it modifies @string in place. Therefore, it cannot be used on
823 	 * statically allocated strings.
824 	 *
825 	 * The pointer to @string is returned to allow the nesting of functions.
826 	 *
827 	 * Also see g_strchomp() and g_strstrip().
828 	 *
829 	 * Params:
830 	 *     string_ = a string to remove the leading whitespace from
831 	 *
832 	 * Returns: @string
833 	 */
834 	public static string strchug(string string_)
835 	{
836 		auto retStr = g_strchug(Str.toStringz(string_));
837 
838 		scope(exit) Str.freeString(retStr);
839 		return Str.toString(retStr);
840 	}
841 
842 	/**
843 	 * Compares @str1 and @str2 like strcmp(). Handles %NULL
844 	 * gracefully by sorting it before non-%NULL strings.
845 	 * Comparing two %NULL pointers returns 0.
846 	 *
847 	 * Params:
848 	 *     str1 = a C string or %NULL
849 	 *     str2 = another C string or %NULL
850 	 *
851 	 * Returns: an integer less than, equal to, or greater than zero, if @str1 is <, == or > than @str2.
852 	 *
853 	 * Since: 2.16
854 	 */
855 	public static int strcmp0(string str1, string str2)
856 	{
857 		return g_strcmp0(Str.toStringz(str1), Str.toStringz(str2));
858 	}
859 
860 	/**
861 	 * Replaces all escaped characters with their one byte equivalent.
862 	 *
863 	 * This function does the reverse conversion of g_strescape().
864 	 *
865 	 * Params:
866 	 *     source = a string to compress
867 	 *
868 	 * Returns: a newly-allocated copy of @source with all escaped
869 	 *     character compressed
870 	 */
871 	public static string strcompress(string source)
872 	{
873 		auto retStr = g_strcompress(Str.toStringz(source));
874 
875 		scope(exit) Str.freeString(retStr);
876 		return Str.toString(retStr);
877 	}
878 
879 	/**
880 	 * Converts any delimiter characters in @string to @new_delimiter.
881 	 * Any characters in @string which are found in @delimiters are
882 	 * changed to the @new_delimiter character. Modifies @string in place,
883 	 * and returns @string itself, not a copy. The return value is to
884 	 * allow nesting such as
885 	 * |[<!-- language="C" -->
886 	 * g_ascii_strup (g_strdelimit (str, "abc", '?'))
887 	 * ]|
888 	 *
889 	 * In order to modify a copy, you may use `g_strdup()`:
890 	 * |[<!-- language="C" -->
891 	 * reformatted = g_strdelimit (g_strdup (const_str), "abc", '?');
892 	 * ...
893 	 * g_free (reformatted);
894 	 * ]|
895 	 *
896 	 * Params:
897 	 *     string_ = the string to convert
898 	 *     delimiters = a string containing the current delimiters,
899 	 *         or %NULL to use the standard delimiters defined in #G_STR_DELIMITERS
900 	 *     newDelimiter = the new delimiter character
901 	 *
902 	 * Returns: @string
903 	 */
904 	public static string strdelimit(string string_, string delimiters, char newDelimiter)
905 	{
906 		auto retStr = g_strdelimit(Str.toStringz(string_), Str.toStringz(delimiters), newDelimiter);
907 
908 		scope(exit) Str.freeString(retStr);
909 		return Str.toString(retStr);
910 	}
911 
912 	/**
913 	 * Converts a string to lower case.
914 	 *
915 	 * Deprecated: This function is totally broken for the reasons discussed
916 	 * in the g_strncasecmp() docs - use g_ascii_strdown() or g_utf8_strdown()
917 	 * instead.
918 	 *
919 	 * Params:
920 	 *     string_ = the string to convert.
921 	 *
922 	 * Returns: the string
923 	 */
924 	public static string strdown(string string_)
925 	{
926 		auto retStr = g_strdown(Str.toStringz(string_));
927 
928 		scope(exit) Str.freeString(retStr);
929 		return Str.toString(retStr);
930 	}
931 
932 	/**
933 	 * Duplicates a string. If @str is %NULL it returns %NULL.
934 	 * The returned string should be freed with g_free()
935 	 * when no longer needed.
936 	 *
937 	 * Params:
938 	 *     str = the string to duplicate
939 	 *
940 	 * Returns: a newly-allocated copy of @str
941 	 */
942 	public static string strdup(string str)
943 	{
944 		auto retStr = g_strdup(Str.toStringz(str));
945 
946 		scope(exit) Str.freeString(retStr);
947 		return Str.toString(retStr);
948 	}
949 
950 	/**
951 	 * Similar to the standard C vsprintf() function but safer, since it
952 	 * calculates the maximum space required and allocates memory to hold
953 	 * the result. The returned string should be freed with g_free() when
954 	 * no longer needed.
955 	 *
956 	 * The returned string is guaranteed to be non-NULL, unless @format
957 	 * contains `%lc` or `%ls` conversions, which can fail if no multibyte
958 	 * representation is available for the given character.
959 	 *
960 	 * See also g_vasprintf(), which offers the same functionality, but
961 	 * additionally returns the length of the allocated string.
962 	 *
963 	 * Params:
964 	 *     format = a standard printf() format string, but notice
965 	 *         [string precision pitfalls][string-precision]
966 	 *     args = the list of parameters to insert into the format string
967 	 *
968 	 * Returns: a newly-allocated string holding the result
969 	 */
970 	public static string strdupVprintf(string format, void* args)
971 	{
972 		auto retStr = g_strdup_vprintf(Str.toStringz(format), args);
973 
974 		scope(exit) Str.freeString(retStr);
975 		return Str.toString(retStr);
976 	}
977 
978 	/**
979 	 * Copies %NULL-terminated array of strings. The copy is a deep copy;
980 	 * the new array should be freed by first freeing each string, then
981 	 * the array itself. g_strfreev() does this for you. If called
982 	 * on a %NULL value, g_strdupv() simply returns %NULL.
983 	 *
984 	 * Params:
985 	 *     strArray = a %NULL-terminated array of strings
986 	 *
987 	 * Returns: a new %NULL-terminated array of strings.
988 	 */
989 	public static string[] strdupv(string[] strArray)
990 	{
991 		return Str.toStringArray(g_strdupv(Str.toStringzArray(strArray)));
992 	}
993 
994 	/**
995 	 * Returns a string corresponding to the given error code, e.g. "no
996 	 * such process". Unlike strerror(), this always returns a string in
997 	 * UTF-8 encoding, and the pointer is guaranteed to remain valid for
998 	 * the lifetime of the process.
999 	 *
1000 	 * Note that the string may be translated according to the current locale.
1001 	 *
1002 	 * The value of %errno will not be changed by this function. However, it may
1003 	 * be changed by intermediate function calls, so you should save its value
1004 	 * as soon as the call returns:
1005 	 * |[
1006 	 * int saved_errno;
1007 	 *
1008 	 * ret = read (blah);
1009 	 * saved_errno = errno;
1010 	 *
1011 	 * g_strerror (saved_errno);
1012 	 * ]|
1013 	 *
1014 	 * Params:
1015 	 *     errnum = the system error number. See the standard C %errno
1016 	 *         documentation
1017 	 *
1018 	 * Returns: a UTF-8 string describing the error code. If the error code
1019 	 *     is unknown, it returns a string like "unknown error (<code>)".
1020 	 */
1021 	public static string strerror(int errnum)
1022 	{
1023 		return Str.toString(g_strerror(errnum));
1024 	}
1025 
1026 	/**
1027 	 * Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\'
1028 	 * and '"' in the string @source by inserting a '\' before
1029 	 * them. Additionally all characters in the range 0x01-0x1F (everything
1030 	 * below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are
1031 	 * replaced with a '\' followed by their octal representation.
1032 	 * Characters supplied in @exceptions are not escaped.
1033 	 *
1034 	 * g_strcompress() does the reverse conversion.
1035 	 *
1036 	 * Params:
1037 	 *     source = a string to escape
1038 	 *     exceptions = a string of characters not to escape in @source
1039 	 *
1040 	 * Returns: a newly-allocated copy of @source with certain
1041 	 *     characters escaped. See above.
1042 	 */
1043 	public static string strescape(string source, string exceptions)
1044 	{
1045 		auto retStr = g_strescape(Str.toStringz(source), Str.toStringz(exceptions));
1046 
1047 		scope(exit) Str.freeString(retStr);
1048 		return Str.toString(retStr);
1049 	}
1050 
1051 	/**
1052 	 * Frees a %NULL-terminated array of strings, as well as each
1053 	 * string it contains.
1054 	 *
1055 	 * If @str_array is %NULL, this function simply returns.
1056 	 *
1057 	 * Params:
1058 	 *     strArray = a %NULL-terminated array of strings to free
1059 	 */
1060 	public static void strfreev(string[] strArray)
1061 	{
1062 		g_strfreev(Str.toStringzArray(strArray));
1063 	}
1064 
1065 	/**
1066 	 * Joins a number of strings together to form one long string, with the
1067 	 * optional @separator inserted between each of them. The returned string
1068 	 * should be freed with g_free().
1069 	 *
1070 	 * If @str_array has no items, the return value will be an
1071 	 * empty string. If @str_array contains a single item, @separator will not
1072 	 * appear in the resulting string.
1073 	 *
1074 	 * Params:
1075 	 *     separator = a string to insert between each of the
1076 	 *         strings, or %NULL
1077 	 *     strArray = a %NULL-terminated array of strings to join
1078 	 *
1079 	 * Returns: a newly-allocated string containing all of the strings joined
1080 	 *     together, with @separator between them
1081 	 */
1082 	public static string strjoinv(string separator, string[] strArray)
1083 	{
1084 		auto retStr = g_strjoinv(Str.toStringz(separator), Str.toStringzArray(strArray));
1085 
1086 		scope(exit) Str.freeString(retStr);
1087 		return Str.toString(retStr);
1088 	}
1089 
1090 	/**
1091 	 * Portability wrapper that calls strlcat() on systems which have it,
1092 	 * and emulates it otherwise. Appends nul-terminated @src string to @dest,
1093 	 * guaranteeing nul-termination for @dest. The total size of @dest won't
1094 	 * exceed @dest_size.
1095 	 *
1096 	 * At most @dest_size - 1 characters will be copied. Unlike strncat(),
1097 	 * @dest_size is the full size of dest, not the space left over. This
1098 	 * function does not allocate memory. It always nul-terminates (unless
1099 	 * @dest_size == 0 or there were no nul characters in the @dest_size
1100 	 * characters of dest to start with).
1101 	 *
1102 	 * Caveat: this is supposedly a more secure alternative to strcat() or
1103 	 * strncat(), but for real security g_strconcat() is harder to mess up.
1104 	 *
1105 	 * Params:
1106 	 *     dest = destination buffer, already containing one nul-terminated string
1107 	 *     src = source buffer
1108 	 *     destSize = length of @dest buffer in bytes (not length of existing string
1109 	 *         inside @dest)
1110 	 *
1111 	 * Returns: size of attempted result, which is MIN (dest_size, strlen
1112 	 *     (original dest)) + strlen (src), so if retval >= dest_size,
1113 	 *     truncation occurred.
1114 	 */
1115 	public static size_t strlcat(string dest, string src, size_t destSize)
1116 	{
1117 		return g_strlcat(Str.toStringz(dest), Str.toStringz(src), destSize);
1118 	}
1119 
1120 	/**
1121 	 * Portability wrapper that calls strlcpy() on systems which have it,
1122 	 * and emulates strlcpy() otherwise. Copies @src to @dest; @dest is
1123 	 * guaranteed to be nul-terminated; @src must be nul-terminated;
1124 	 * @dest_size is the buffer size, not the number of bytes to copy.
1125 	 *
1126 	 * At most @dest_size - 1 characters will be copied. Always nul-terminates
1127 	 * (unless @dest_size is 0). This function does not allocate memory. Unlike
1128 	 * strncpy(), this function doesn't pad @dest (so it's often faster). It
1129 	 * returns the size of the attempted result, strlen (src), so if
1130 	 * @retval >= @dest_size, truncation occurred.
1131 	 *
1132 	 * Caveat: strlcpy() is supposedly more secure than strcpy() or strncpy(),
1133 	 * but if you really want to avoid screwups, g_strdup() is an even better
1134 	 * idea.
1135 	 *
1136 	 * Params:
1137 	 *     dest = destination buffer
1138 	 *     src = source buffer
1139 	 *     destSize = length of @dest in bytes
1140 	 *
1141 	 * Returns: length of @src
1142 	 */
1143 	public static size_t strlcpy(string dest, string src, size_t destSize)
1144 	{
1145 		return g_strlcpy(Str.toStringz(dest), Str.toStringz(src), destSize);
1146 	}
1147 
1148 	/**
1149 	 * A case-insensitive string comparison, corresponding to the standard
1150 	 * strncasecmp() function on platforms which support it. It is similar
1151 	 * to g_strcasecmp() except it only compares the first @n characters of
1152 	 * the strings.
1153 	 *
1154 	 * Deprecated: The problem with g_strncasecmp() is that it does
1155 	 * the comparison by calling toupper()/tolower(). These functions
1156 	 * are locale-specific and operate on single bytes. However, it is
1157 	 * impossible to handle things correctly from an internationalization
1158 	 * standpoint by operating on bytes, since characters may be multibyte.
1159 	 * Thus g_strncasecmp() is broken if your string is guaranteed to be
1160 	 * ASCII, since it is locale-sensitive, and it's broken if your string
1161 	 * is localized, since it doesn't work on many encodings at all,
1162 	 * including UTF-8, EUC-JP, etc.
1163 	 *
1164 	 * There are therefore two replacement techniques: g_ascii_strncasecmp(),
1165 	 * which only works on ASCII and is not locale-sensitive, and
1166 	 * g_utf8_casefold() followed by strcmp() on the resulting strings,
1167 	 * which is good for case-insensitive sorting of UTF-8.
1168 	 *
1169 	 * Params:
1170 	 *     s1 = a string
1171 	 *     s2 = a string to compare with @s1
1172 	 *     n = the maximum number of characters to compare
1173 	 *
1174 	 * Returns: 0 if the strings match, a negative value if @s1 < @s2,
1175 	 *     or a positive value if @s1 > @s2.
1176 	 */
1177 	public static int strncasecmp(string s1, string s2, uint n)
1178 	{
1179 		return g_strncasecmp(Str.toStringz(s1), Str.toStringz(s2), n);
1180 	}
1181 
1182 	/**
1183 	 * Duplicates the first @n bytes of a string, returning a newly-allocated
1184 	 * buffer @n + 1 bytes long which will always be nul-terminated. If @str
1185 	 * is less than @n bytes long the buffer is padded with nuls. If @str is
1186 	 * %NULL it returns %NULL. The returned value should be freed when no longer
1187 	 * needed.
1188 	 *
1189 	 * To copy a number of characters from a UTF-8 encoded string,
1190 	 * use g_utf8_strncpy() instead.
1191 	 *
1192 	 * Params:
1193 	 *     str = the string to duplicate
1194 	 *     n = the maximum number of bytes to copy from @str
1195 	 *
1196 	 * Returns: a newly-allocated buffer containing the first @n bytes
1197 	 *     of @str, nul-terminated
1198 	 */
1199 	public static string strndup(string str, size_t n)
1200 	{
1201 		auto retStr = g_strndup(Str.toStringz(str), n);
1202 
1203 		scope(exit) Str.freeString(retStr);
1204 		return Str.toString(retStr);
1205 	}
1206 
1207 	/**
1208 	 * Creates a new string @length bytes long filled with @fill_char.
1209 	 * The returned string should be freed when no longer needed.
1210 	 *
1211 	 * Params:
1212 	 *     length = the length of the new string
1213 	 *     fillChar = the byte to fill the string with
1214 	 *
1215 	 * Returns: a newly-allocated string filled the @fill_char
1216 	 */
1217 	public static string strnfill(size_t length, char fillChar)
1218 	{
1219 		auto retStr = g_strnfill(length, fillChar);
1220 
1221 		scope(exit) Str.freeString(retStr);
1222 		return Str.toString(retStr);
1223 	}
1224 
1225 	/**
1226 	 * Reverses all of the bytes in a string. For example,
1227 	 * `g_strreverse ("abcdef")` will result in "fedcba".
1228 	 *
1229 	 * Note that g_strreverse() doesn't work on UTF-8 strings
1230 	 * containing multibyte characters. For that purpose, use
1231 	 * g_utf8_strreverse().
1232 	 *
1233 	 * Params:
1234 	 *     string_ = the string to reverse
1235 	 *
1236 	 * Returns: the same pointer passed in as @string
1237 	 */
1238 	public static string strreverse(string string_)
1239 	{
1240 		auto retStr = g_strreverse(Str.toStringz(string_));
1241 
1242 		scope(exit) Str.freeString(retStr);
1243 		return Str.toString(retStr);
1244 	}
1245 
1246 	/**
1247 	 * Searches the string @haystack for the last occurrence
1248 	 * of the string @needle.
1249 	 *
1250 	 * Params:
1251 	 *     haystack = a nul-terminated string
1252 	 *     needle = the nul-terminated string to search for
1253 	 *
1254 	 * Returns: a pointer to the found occurrence, or
1255 	 *     %NULL if not found.
1256 	 */
1257 	public static string strrstr(string haystack, string needle)
1258 	{
1259 		auto retStr = g_strrstr(Str.toStringz(haystack), Str.toStringz(needle));
1260 
1261 		scope(exit) Str.freeString(retStr);
1262 		return Str.toString(retStr);
1263 	}
1264 
1265 	/**
1266 	 * Searches the string @haystack for the last occurrence
1267 	 * of the string @needle, limiting the length of the search
1268 	 * to @haystack_len.
1269 	 *
1270 	 * Params:
1271 	 *     haystack = a nul-terminated string
1272 	 *     haystackLen = the maximum length of @haystack
1273 	 *     needle = the nul-terminated string to search for
1274 	 *
1275 	 * Returns: a pointer to the found occurrence, or
1276 	 *     %NULL if not found.
1277 	 */
1278 	public static string strrstrLen(string haystack, ptrdiff_t haystackLen, string needle)
1279 	{
1280 		auto retStr = g_strrstr_len(Str.toStringz(haystack), haystackLen, Str.toStringz(needle));
1281 
1282 		scope(exit) Str.freeString(retStr);
1283 		return Str.toString(retStr);
1284 	}
1285 
1286 	/**
1287 	 * Returns a string describing the given signal, e.g. "Segmentation fault".
1288 	 * You should use this function in preference to strsignal(), because it
1289 	 * returns a string in UTF-8 encoding, and since not all platforms support
1290 	 * the strsignal() function.
1291 	 *
1292 	 * Params:
1293 	 *     signum = the signal number. See the `signal` documentation
1294 	 *
1295 	 * Returns: a UTF-8 string describing the signal. If the signal is unknown,
1296 	 *     it returns "unknown signal (<signum>)".
1297 	 */
1298 	public static string strsignal(int signum)
1299 	{
1300 		return Str.toString(g_strsignal(signum));
1301 	}
1302 
1303 	/**
1304 	 * Splits a string into a maximum of @max_tokens pieces, using the given
1305 	 * @delimiter. If @max_tokens is reached, the remainder of @string is
1306 	 * appended to the last token.
1307 	 *
1308 	 * As an example, the result of g_strsplit (":a:bc::d:", ":", -1) is a
1309 	 * %NULL-terminated vector containing the six strings "", "a", "bc", "", "d"
1310 	 * and "".
1311 	 *
1312 	 * As a special case, the result of splitting the empty string "" is an empty
1313 	 * vector, not a vector containing a single string. The reason for this
1314 	 * special case is that being able to represent an empty vector is typically
1315 	 * more useful than consistent handling of empty elements. If you do need
1316 	 * to represent empty elements, you'll need to check for the empty string
1317 	 * before calling g_strsplit().
1318 	 *
1319 	 * Params:
1320 	 *     string_ = a string to split
1321 	 *     delimiter = a string which specifies the places at which to split
1322 	 *         the string. The delimiter is not included in any of the resulting
1323 	 *         strings, unless @max_tokens is reached.
1324 	 *     maxTokens = the maximum number of pieces to split @string into.
1325 	 *         If this is less than 1, the string is split completely.
1326 	 *
1327 	 * Returns: a newly-allocated %NULL-terminated array of strings. Use
1328 	 *     g_strfreev() to free it.
1329 	 */
1330 	public static string[] strsplit(string string_, string delimiter, int maxTokens)
1331 	{
1332 		return Str.toStringArray(g_strsplit(Str.toStringz(string_), Str.toStringz(delimiter), maxTokens));
1333 	}
1334 
1335 	/**
1336 	 * Splits @string into a number of tokens not containing any of the characters
1337 	 * in @delimiter. A token is the (possibly empty) longest string that does not
1338 	 * contain any of the characters in @delimiters. If @max_tokens is reached, the
1339 	 * remainder is appended to the last token.
1340 	 *
1341 	 * For example the result of g_strsplit_set ("abc:def/ghi", ":/", -1) is a
1342 	 * %NULL-terminated vector containing the three strings "abc", "def",
1343 	 * and "ghi".
1344 	 *
1345 	 * The result of g_strsplit_set (":def/ghi:", ":/", -1) is a %NULL-terminated
1346 	 * vector containing the four strings "", "def", "ghi", and "".
1347 	 *
1348 	 * As a special case, the result of splitting the empty string "" is an empty
1349 	 * vector, not a vector containing a single string. The reason for this
1350 	 * special case is that being able to represent an empty vector is typically
1351 	 * more useful than consistent handling of empty elements. If you do need
1352 	 * to represent empty elements, you'll need to check for the empty string
1353 	 * before calling g_strsplit_set().
1354 	 *
1355 	 * Note that this function works on bytes not characters, so it can't be used
1356 	 * to delimit UTF-8 strings for anything but ASCII characters.
1357 	 *
1358 	 * Params:
1359 	 *     string_ = The string to be tokenized
1360 	 *     delimiters = A nul-terminated string containing bytes that are used
1361 	 *         to split the string.
1362 	 *     maxTokens = The maximum number of tokens to split @string into.
1363 	 *         If this is less than 1, the string is split completely
1364 	 *
1365 	 * Returns: a newly-allocated %NULL-terminated array of strings. Use
1366 	 *     g_strfreev() to free it.
1367 	 *
1368 	 * Since: 2.4
1369 	 */
1370 	public static string[] strsplitSet(string string_, string delimiters, int maxTokens)
1371 	{
1372 		return Str.toStringArray(g_strsplit_set(Str.toStringz(string_), Str.toStringz(delimiters), maxTokens));
1373 	}
1374 
1375 	/**
1376 	 * Searches the string @haystack for the first occurrence
1377 	 * of the string @needle, limiting the length of the search
1378 	 * to @haystack_len.
1379 	 *
1380 	 * Params:
1381 	 *     haystack = a string
1382 	 *     haystackLen = the maximum length of @haystack. Note that -1 is
1383 	 *         a valid length, if @haystack is nul-terminated, meaning it will
1384 	 *         search through the whole string.
1385 	 *     needle = the string to search for
1386 	 *
1387 	 * Returns: a pointer to the found occurrence, or
1388 	 *     %NULL if not found.
1389 	 */
1390 	public static string strstrLen(string haystack, ptrdiff_t haystackLen, string needle)
1391 	{
1392 		auto retStr = g_strstr_len(Str.toStringz(haystack), haystackLen, Str.toStringz(needle));
1393 
1394 		scope(exit) Str.freeString(retStr);
1395 		return Str.toString(retStr);
1396 	}
1397 
1398 	/**
1399 	 * Converts a string to a #gdouble value.
1400 	 * It calls the standard strtod() function to handle the conversion, but
1401 	 * if the string is not completely converted it attempts the conversion
1402 	 * again with g_ascii_strtod(), and returns the best match.
1403 	 *
1404 	 * This function should seldom be used. The normal situation when reading
1405 	 * numbers not for human consumption is to use g_ascii_strtod(). Only when
1406 	 * you know that you must expect both locale formatted and C formatted numbers
1407 	 * should you use this. Make sure that you don't pass strings such as comma
1408 	 * separated lists of values, since the commas may be interpreted as a decimal
1409 	 * point in some locales, causing unexpected results.
1410 	 *
1411 	 * Params:
1412 	 *     nptr = the string to convert to a numeric value.
1413 	 *     endptr = if non-%NULL, it returns the
1414 	 *         character after the last character used in the conversion.
1415 	 *
1416 	 * Returns: the #gdouble value.
1417 	 */
1418 	public static double strtod(string nptr, out string endptr)
1419 	{
1420 		char* outendptr = null;
1421 
1422 		auto __p = g_strtod(Str.toStringz(nptr), &outendptr);
1423 
1424 		endptr = Str.toString(outendptr);
1425 
1426 		return __p;
1427 	}
1428 
1429 	/**
1430 	 * Converts a string to upper case.
1431 	 *
1432 	 * Deprecated: This function is totally broken for the reasons
1433 	 * discussed in the g_strncasecmp() docs - use g_ascii_strup()
1434 	 * or g_utf8_strup() instead.
1435 	 *
1436 	 * Params:
1437 	 *     string_ = the string to convert
1438 	 *
1439 	 * Returns: the string
1440 	 */
1441 	public static string strup(string string_)
1442 	{
1443 		auto retStr = g_strup(Str.toStringz(string_));
1444 
1445 		scope(exit) Str.freeString(retStr);
1446 		return Str.toString(retStr);
1447 	}
1448 
1449 	/** */
1450 	public static GType strvGetType()
1451 	{
1452 		return g_strv_get_type();
1453 	}
1454 
1455 	/**
1456 	 * Returns the length of the given %NULL-terminated
1457 	 * string array @str_array. @str_array must not be %NULL.
1458 	 *
1459 	 * Params:
1460 	 *     strArray = a %NULL-terminated array of strings
1461 	 *
1462 	 * Returns: length of @str_array.
1463 	 *
1464 	 * Since: 2.6
1465 	 */
1466 	public static uint strvLength(string[] strArray)
1467 	{
1468 		return g_strv_length(Str.toStringzArray(strArray));
1469 	}
1470 
1471 	/**
1472 	 * Checks if @strv contains @str. @strv must not be %NULL.
1473 	 *
1474 	 * Params:
1475 	 *     strv = a %NULL-terminated array of strings
1476 	 *     str = a string
1477 	 *
1478 	 * Returns: %TRUE if @str is an element of @strv, according to g_str_equal().
1479 	 *
1480 	 * Since: 2.44
1481 	 */
1482 	public static bool strvContains(string strv, string str)
1483 	{
1484 		return g_strv_contains(Str.toStringz(strv), Str.toStringz(str)) != 0;
1485 	}
1486 
1487 	/**
1488 	 * An implementation of the GNU vasprintf() function which supports
1489 	 * positional parameters, as specified in the Single Unix Specification.
1490 	 * This function is similar to g_vsprintf(), except that it allocates a
1491 	 * string to hold the output, instead of putting the output in a buffer
1492 	 * you allocate in advance.
1493 	 *
1494 	 * The returned value in @string is guaranteed to be non-NULL, unless
1495 	 * @format contains `%lc` or `%ls` conversions, which can fail if no
1496 	 * multibyte representation is available for the given character.
1497 	 *
1498 	 * `glib/gprintf.h` must be explicitly included in order to use this function.
1499 	 *
1500 	 * Params:
1501 	 *     string_ = the return location for the newly-allocated string.
1502 	 *     format = a standard printf() format string, but notice
1503 	 *         [string precision pitfalls][string-precision]
1504 	 *     args = the list of arguments to insert in the output.
1505 	 *
1506 	 * Returns: the number of bytes printed.
1507 	 *
1508 	 * Since: 2.4
1509 	 */
1510 	public static int vasprintf(string[] string_, string format, void* args)
1511 	{
1512 		return g_vasprintf(Str.toStringzArray(string_), Str.toStringz(format), args);
1513 	}
1514 
1515 	/**
1516 	 * An implementation of the standard vprintf() function which supports
1517 	 * positional parameters, as specified in the Single Unix Specification.
1518 	 *
1519 	 * `glib/gprintf.h` must be explicitly included in order to use this function.
1520 	 *
1521 	 * Params:
1522 	 *     format = a standard printf() format string, but notice
1523 	 *         [string precision pitfalls][string-precision]
1524 	 *     args = the list of arguments to insert in the output.
1525 	 *
1526 	 * Returns: the number of bytes printed.
1527 	 *
1528 	 * Since: 2.2
1529 	 */
1530 	public static int vprintf(string format, void* args)
1531 	{
1532 		return g_vprintf(Str.toStringz(format), args);
1533 	}
1534 
1535 	/**
1536 	 * A safer form of the standard vsprintf() function. The output is guaranteed
1537 	 * to not exceed @n characters (including the terminating nul character), so
1538 	 * it is easy to ensure that a buffer overflow cannot occur.
1539 	 *
1540 	 * See also g_strdup_vprintf().
1541 	 *
1542 	 * In versions of GLib prior to 1.2.3, this function may return -1 if the
1543 	 * output was truncated, and the truncated string may not be nul-terminated.
1544 	 * In versions prior to 1.3.12, this function returns the length of the output
1545 	 * string.
1546 	 *
1547 	 * The return value of g_vsnprintf() conforms to the vsnprintf() function
1548 	 * as standardized in ISO C99. Note that this is different from traditional
1549 	 * vsnprintf(), which returns the length of the output string.
1550 	 *
1551 	 * The format string may contain positional parameters, as specified in
1552 	 * the Single Unix Specification.
1553 	 *
1554 	 * Params:
1555 	 *     string_ = the buffer to hold the output.
1556 	 *     n = the maximum number of bytes to produce (including the
1557 	 *         terminating nul character).
1558 	 *     format = a standard printf() format string, but notice
1559 	 *         string precision pitfalls][string-precision]
1560 	 *     args = the list of arguments to insert in the output.
1561 	 *
1562 	 * Returns: the number of bytes which would be produced if the buffer
1563 	 *     was large enough.
1564 	 */
1565 	public static int vsnprintf(string string_, gulong n, string format, void* args)
1566 	{
1567 		return g_vsnprintf(Str.toStringz(string_), n, Str.toStringz(format), args);
1568 	}
1569 
1570 	/**
1571 	 * An implementation of the standard vsprintf() function which supports
1572 	 * positional parameters, as specified in the Single Unix Specification.
1573 	 *
1574 	 * `glib/gprintf.h` must be explicitly included in order to use this function.
1575 	 *
1576 	 * Params:
1577 	 *     string_ = the buffer to hold the output.
1578 	 *     format = a standard printf() format string, but notice
1579 	 *         [string precision pitfalls][string-precision]
1580 	 *     args = the list of arguments to insert in the output.
1581 	 *
1582 	 * Returns: the number of bytes printed.
1583 	 *
1584 	 * Since: 2.2
1585 	 */
1586 	public static int vsprintf(string string_, string format, void* args)
1587 	{
1588 		return g_vsprintf(Str.toStringz(string_), Str.toStringz(format), args);
1589 	}
1590 
1591 	/**
1592 	 * An implementation of the standard fprintf() function which supports
1593 	 * positional parameters, as specified in the Single Unix Specification.
1594 	 *
1595 	 * `glib/gprintf.h` must be explicitly included in order to use this function.
1596 	 *
1597 	 * Params:
1598 	 *     file = the stream to write to.
1599 	 *     format = a standard printf() format string, but notice
1600 	 *         [string precision pitfalls][string-precision]
1601 	 *     args = the list of arguments to insert in the output.
1602 	 *
1603 	 * Returns: the number of bytes printed.
1604 	 *
1605 	 * Since: 2.2
1606 	 */
1607 	public static int vfprintf(FILE* file, string format, void* args)
1608 	{
1609 		return g_vfprintf(file, Str.toStringz(format), args);
1610 	}
1611 
1612 	/**
1613 	 * A convenience function for converting a string to a signed number.
1614 	 *
1615 	 * This function assumes that @str contains only a number of the given
1616 	 * @base that is within inclusive bounds limited by @min and @max. If
1617 	 * this is true, then the converted number is stored in @out_num. An
1618 	 * empty string is not a valid input. A string with leading or
1619 	 * trailing whitespace is also an invalid input.
1620 	 *
1621 	 * @base can be between 2 and 36 inclusive. Hexadecimal numbers must
1622 	 * not be prefixed with "0x" or "0X". Such a problem does not exist
1623 	 * for octal numbers, since they were usually prefixed with a zero
1624 	 * which does not change the value of the parsed number.
1625 	 *
1626 	 * Parsing failures result in an error with the %G_NUMBER_PARSER_ERROR
1627 	 * domain. If the input is invalid, the error code will be
1628 	 * %G_NUMBER_PARSER_ERROR_INVALID. If the parsed number is out of
1629 	 * bounds - %G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS.
1630 	 *
1631 	 * See g_ascii_strtoll() if you have more complex needs such as
1632 	 * parsing a string which starts with a number, but then has other
1633 	 * characters.
1634 	 *
1635 	 * Params:
1636 	 *     str = a string
1637 	 *     base = base of a parsed number
1638 	 *     min = a lower bound (inclusive)
1639 	 *     max = an upper bound (inclusive)
1640 	 *     outNum = a return location for a number
1641 	 *
1642 	 * Returns: %TRUE if @str was a number, otherwise %FALSE.
1643 	 *
1644 	 * Since: 2.54
1645 	 *
1646 	 * Throws: GException on failure.
1647 	 */
1648 	public static bool asciiStringToSigned(string str, uint base, long min, long max, out long outNum)
1649 	{
1650 		GError* err = null;
1651 
1652 		auto __p = g_ascii_string_to_signed(Str.toStringz(str), base, min, max, &outNum, &err) != 0;
1653 
1654 		if (err !is null)
1655 		{
1656 			throw new GException( new ErrorG(err) );
1657 		}
1658 
1659 		return __p;
1660 	}
1661 
1662 	/**
1663 	 * A convenience function for converting a string to an unsigned number.
1664 	 *
1665 	 * This function assumes that @str contains only a number of the given
1666 	 * @base that is within inclusive bounds limited by @min and @max. If
1667 	 * this is true, then the converted number is stored in @out_num. An
1668 	 * empty string is not a valid input. A string with leading or
1669 	 * trailing whitespace is also an invalid input. A string with a leading sign
1670 	 * (`-` or `+`) is not a valid input for the unsigned parser.
1671 	 *
1672 	 * @base can be between 2 and 36 inclusive. Hexadecimal numbers must
1673 	 * not be prefixed with "0x" or "0X". Such a problem does not exist
1674 	 * for octal numbers, since they were usually prefixed with a zero
1675 	 * which does not change the value of the parsed number.
1676 	 *
1677 	 * Parsing failures result in an error with the %G_NUMBER_PARSER_ERROR
1678 	 * domain. If the input is invalid, the error code will be
1679 	 * %G_NUMBER_PARSER_ERROR_INVALID. If the parsed number is out of
1680 	 * bounds - %G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS.
1681 	 *
1682 	 * See g_ascii_strtoull() if you have more complex needs such as
1683 	 * parsing a string which starts with a number, but then has other
1684 	 * characters.
1685 	 *
1686 	 * Params:
1687 	 *     str = a string
1688 	 *     base = base of a parsed number
1689 	 *     min = a lower bound (inclusive)
1690 	 *     max = an upper bound (inclusive)
1691 	 *     outNum = a return location for a number
1692 	 *
1693 	 * Returns: %TRUE if @str was a number, otherwise %FALSE.
1694 	 *
1695 	 * Since: 2.54
1696 	 *
1697 	 * Throws: GException on failure.
1698 	 */
1699 	public static bool asciiStringToUnsigned(string str, uint base, ulong min, ulong max, out ulong outNum)
1700 	{
1701 		GError* err = null;
1702 
1703 		auto __p = g_ascii_string_to_unsigned(Str.toStringz(str), base, min, max, &outNum, &err) != 0;
1704 
1705 		if (err !is null)
1706 		{
1707 			throw new GException( new ErrorG(err) );
1708 		}
1709 
1710 		return __p;
1711 	}
1712 
1713 	/**
1714 	 * Checks if @strv1 and @strv2 contain exactly the same elements in exactly the
1715 	 * same order. Elements are compared using g_str_equal(). To match independently
1716 	 * of order, sort the arrays first (using g_qsort_with_data() or similar).
1717 	 *
1718 	 * Two empty arrays are considered equal. Neither @strv1 not @strv2 may be
1719 	 * %NULL.
1720 	 *
1721 	 * Params:
1722 	 *     strv1 = a %NULL-terminated array of strings
1723 	 *     strv2 = another %NULL-terminated array of strings
1724 	 *
1725 	 * Returns: %TRUE if @strv1 and @strv2 are equal
1726 	 *
1727 	 * Since: 2.60
1728 	 */
1729 	public static bool strvEqual(string strv1, string strv2)
1730 	{
1731 		return g_strv_equal(Str.toStringz(strv1), Str.toStringz(strv2)) != 0;
1732 	}
1733 }