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