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.StringG; 26 27 private import glib.Bytes; 28 private import glib.Str; 29 private import glib.c.functions; 30 public import glib.c.types; 31 32 33 /** 34 * The GString struct contains the public fields of a GString. 35 */ 36 public class StringG 37 { 38 /** the main Gtk struct */ 39 protected GString* gString; 40 protected bool ownedRef; 41 42 /** Get the main Gtk struct */ 43 public GString* getStringGStruct(bool transferOwnership = false) 44 { 45 if (transferOwnership) 46 ownedRef = false; 47 return gString; 48 } 49 50 /** the main Gtk struct as a void* */ 51 protected void* getStruct() 52 { 53 return cast(void*)gString; 54 } 55 56 /** 57 * Sets our main struct and passes it to the parent class. 58 */ 59 public this (GString* gString, bool ownedRef = false) 60 { 61 this.gString = gString; 62 this.ownedRef = ownedRef; 63 } 64 65 66 /** 67 * Adds a string onto the end of a #GString, expanding 68 * it if necessary. 69 * 70 * Params: 71 * val = the string to append onto the end of @string 72 * 73 * Returns: @string 74 */ 75 public StringG append(string val) 76 { 77 auto __p = g_string_append(gString, Str.toStringz(val)); 78 79 if(__p is null) 80 { 81 return null; 82 } 83 84 return new StringG(cast(GString*) __p); 85 } 86 87 /** 88 * Adds a byte onto the end of a #GString, expanding 89 * it if necessary. 90 * 91 * Params: 92 * c = the byte to append onto the end of @string 93 * 94 * Returns: @string 95 */ 96 public StringG appendC(char c) 97 { 98 auto __p = g_string_append_c(gString, c); 99 100 if(__p is null) 101 { 102 return null; 103 } 104 105 return new StringG(cast(GString*) __p); 106 } 107 108 /** 109 * Appends @len bytes of @val to @string. 110 * 111 * If @len is positive, @val may contain embedded nuls and need 112 * not be nul-terminated. It is the caller's responsibility to 113 * ensure that @val has at least @len addressable bytes. 114 * 115 * If @len is negative, @val must be nul-terminated and @len 116 * is considered to request the entire string length. This 117 * makes g_string_append_len() equivalent to g_string_append(). 118 * 119 * Params: 120 * val = bytes to append 121 * len = number of bytes of @val to use, or -1 for all of @val 122 * 123 * Returns: @string 124 */ 125 public StringG appendLen(string val, ptrdiff_t len) 126 { 127 auto __p = g_string_append_len(gString, Str.toStringz(val), len); 128 129 if(__p is null) 130 { 131 return null; 132 } 133 134 return new StringG(cast(GString*) __p); 135 } 136 137 /** 138 * Converts a Unicode character into UTF-8, and appends it 139 * to the string. 140 * 141 * Params: 142 * wc = a Unicode character 143 * 144 * Returns: @string 145 */ 146 public StringG appendUnichar(dchar wc) 147 { 148 auto __p = g_string_append_unichar(gString, wc); 149 150 if(__p is null) 151 { 152 return null; 153 } 154 155 return new StringG(cast(GString*) __p); 156 } 157 158 /** 159 * Appends @unescaped to @string, escaping any characters that 160 * are reserved in URIs using URI-style escape sequences. 161 * 162 * Params: 163 * unescaped = a string 164 * reservedCharsAllowed = a string of reserved characters allowed 165 * to be used, or %NULL 166 * allowUtf8 = set %TRUE if the escaped string may include UTF8 characters 167 * 168 * Returns: @string 169 * 170 * Since: 2.16 171 */ 172 public StringG appendUriEscaped(string unescaped, string reservedCharsAllowed, bool allowUtf8) 173 { 174 auto __p = g_string_append_uri_escaped(gString, Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8); 175 176 if(__p is null) 177 { 178 return null; 179 } 180 181 return new StringG(cast(GString*) __p); 182 } 183 184 /** 185 * Appends a formatted string onto the end of a #GString. 186 * This function is similar to g_string_append_printf() 187 * except that the arguments to the format string are passed 188 * as a va_list. 189 * 190 * Params: 191 * format = the string format. See the printf() documentation 192 * args = the list of arguments to insert in the output 193 * 194 * Since: 2.14 195 */ 196 public void appendVprintf(string format, void* args) 197 { 198 g_string_append_vprintf(gString, Str.toStringz(format), args); 199 } 200 201 /** 202 * Converts all uppercase ASCII letters to lowercase ASCII letters. 203 * 204 * Returns: passed-in @string pointer, with all the 205 * uppercase characters converted to lowercase in place, 206 * with semantics that exactly match g_ascii_tolower(). 207 */ 208 public StringG asciiDown() 209 { 210 auto __p = g_string_ascii_down(gString); 211 212 if(__p is null) 213 { 214 return null; 215 } 216 217 return new StringG(cast(GString*) __p); 218 } 219 220 /** 221 * Converts all lowercase ASCII letters to uppercase ASCII letters. 222 * 223 * Returns: passed-in @string pointer, with all the 224 * lowercase characters converted to uppercase in place, 225 * with semantics that exactly match g_ascii_toupper(). 226 */ 227 public StringG asciiUp() 228 { 229 auto __p = g_string_ascii_up(gString); 230 231 if(__p is null) 232 { 233 return null; 234 } 235 236 return new StringG(cast(GString*) __p); 237 } 238 239 /** 240 * Copies the bytes from a string into a #GString, 241 * destroying any previous contents. It is rather like 242 * the standard strcpy() function, except that you do not 243 * have to worry about having enough space to copy the string. 244 * 245 * Params: 246 * rval = the string to copy into @string 247 * 248 * Returns: @string 249 */ 250 public StringG assign(string rval) 251 { 252 auto __p = g_string_assign(gString, Str.toStringz(rval)); 253 254 if(__p is null) 255 { 256 return null; 257 } 258 259 return new StringG(cast(GString*) __p); 260 } 261 262 /** 263 * Converts a #GString to lowercase. 264 * 265 * Deprecated: This function uses the locale-specific 266 * tolower() function, which is almost never the right thing. 267 * Use g_string_ascii_down() or g_utf8_strdown() instead. 268 * 269 * Returns: the #GString 270 */ 271 public StringG down() 272 { 273 auto __p = g_string_down(gString); 274 275 if(__p is null) 276 { 277 return null; 278 } 279 280 return new StringG(cast(GString*) __p); 281 } 282 283 /** 284 * Compares two strings for equality, returning %TRUE if they are equal. 285 * For use with #GHashTable. 286 * 287 * Params: 288 * v2 = another #GString 289 * 290 * Returns: %TRUE if the strings are the same length and contain the 291 * same bytes 292 */ 293 public bool equal(StringG v2) 294 { 295 return g_string_equal(gString, (v2 is null) ? null : v2.getStringGStruct()) != 0; 296 } 297 298 /** 299 * Removes @len bytes from a #GString, starting at position @pos. 300 * The rest of the #GString is shifted down to fill the gap. 301 * 302 * Params: 303 * pos = the position of the content to remove 304 * len = the number of bytes to remove, or -1 to remove all 305 * following bytes 306 * 307 * Returns: @string 308 */ 309 public StringG erase(ptrdiff_t pos, ptrdiff_t len) 310 { 311 auto __p = g_string_erase(gString, pos, len); 312 313 if(__p is null) 314 { 315 return null; 316 } 317 318 return new StringG(cast(GString*) __p); 319 } 320 321 /** 322 * Frees the memory allocated for the #GString. 323 * If @free_segment is %TRUE it also frees the character data. If 324 * it's %FALSE, the caller gains ownership of the buffer and must 325 * free it after use with g_free(). 326 * 327 * Params: 328 * freeSegment = if %TRUE, the actual character data is freed as well 329 * 330 * Returns: the character data of @string 331 * (i.e. %NULL if @free_segment is %TRUE) 332 */ 333 public string free(bool freeSegment) 334 { 335 auto retStr = g_string_free(gString, freeSegment); 336 337 scope(exit) Str.freeString(retStr); 338 return Str.toString(retStr); 339 } 340 341 /** 342 * Transfers ownership of the contents of @string to a newly allocated 343 * #GBytes. The #GString structure itself is deallocated, and it is 344 * therefore invalid to use @string after invoking this function. 345 * 346 * Note that while #GString ensures that its buffer always has a 347 * trailing nul character (not reflected in its "len"), the returned 348 * #GBytes does not include this extra nul; i.e. it has length exactly 349 * equal to the "len" member. 350 * 351 * Returns: A newly allocated #GBytes containing contents of @string; @string itself is freed 352 * 353 * Since: 2.34 354 */ 355 public Bytes freeToBytes() 356 { 357 auto __p = g_string_free_to_bytes(gString); 358 359 if(__p is null) 360 { 361 return null; 362 } 363 364 return new Bytes(cast(GBytes*) __p, true); 365 } 366 367 /** 368 * Creates a hash code for @str; for use with #GHashTable. 369 * 370 * Returns: hash code for @str 371 */ 372 public uint hash() 373 { 374 return g_string_hash(gString); 375 } 376 377 /** 378 * Inserts a copy of a string into a #GString, 379 * expanding it if necessary. 380 * 381 * Params: 382 * pos = the position to insert the copy of the string 383 * val = the string to insert 384 * 385 * Returns: @string 386 */ 387 public StringG insert(ptrdiff_t pos, string val) 388 { 389 auto __p = g_string_insert(gString, pos, Str.toStringz(val)); 390 391 if(__p is null) 392 { 393 return null; 394 } 395 396 return new StringG(cast(GString*) __p); 397 } 398 399 /** 400 * Inserts a byte into a #GString, expanding it if necessary. 401 * 402 * Params: 403 * pos = the position to insert the byte 404 * c = the byte to insert 405 * 406 * Returns: @string 407 */ 408 public StringG insertC(ptrdiff_t pos, char c) 409 { 410 auto __p = g_string_insert_c(gString, pos, c); 411 412 if(__p is null) 413 { 414 return null; 415 } 416 417 return new StringG(cast(GString*) __p); 418 } 419 420 /** 421 * Inserts @len bytes of @val into @string at @pos. 422 * 423 * If @len is positive, @val may contain embedded nuls and need 424 * not be nul-terminated. It is the caller's responsibility to 425 * ensure that @val has at least @len addressable bytes. 426 * 427 * If @len is negative, @val must be nul-terminated and @len 428 * is considered to request the entire string length. 429 * 430 * If @pos is -1, bytes are inserted at the end of the string. 431 * 432 * Params: 433 * pos = position in @string where insertion should 434 * happen, or -1 for at the end 435 * val = bytes to insert 436 * len = number of bytes of @val to insert, or -1 for all of @val 437 * 438 * Returns: @string 439 */ 440 public StringG insertLen(ptrdiff_t pos, string val, ptrdiff_t len) 441 { 442 auto __p = g_string_insert_len(gString, pos, Str.toStringz(val), len); 443 444 if(__p is null) 445 { 446 return null; 447 } 448 449 return new StringG(cast(GString*) __p); 450 } 451 452 /** 453 * Converts a Unicode character into UTF-8, and insert it 454 * into the string at the given position. 455 * 456 * Params: 457 * pos = the position at which to insert character, or -1 458 * to append at the end of the string 459 * wc = a Unicode character 460 * 461 * Returns: @string 462 */ 463 public StringG insertUnichar(ptrdiff_t pos, dchar wc) 464 { 465 auto __p = g_string_insert_unichar(gString, pos, wc); 466 467 if(__p is null) 468 { 469 return null; 470 } 471 472 return new StringG(cast(GString*) __p); 473 } 474 475 /** 476 * Overwrites part of a string, lengthening it if necessary. 477 * 478 * Params: 479 * pos = the position at which to start overwriting 480 * val = the string that will overwrite the @string starting at @pos 481 * 482 * Returns: @string 483 * 484 * Since: 2.14 485 */ 486 public StringG overwrite(size_t pos, string val) 487 { 488 auto __p = g_string_overwrite(gString, pos, Str.toStringz(val)); 489 490 if(__p is null) 491 { 492 return null; 493 } 494 495 return new StringG(cast(GString*) __p); 496 } 497 498 /** 499 * Overwrites part of a string, lengthening it if necessary. 500 * This function will work with embedded nuls. 501 * 502 * Params: 503 * pos = the position at which to start overwriting 504 * val = the string that will overwrite the @string starting at @pos 505 * len = the number of bytes to write from @val 506 * 507 * Returns: @string 508 * 509 * Since: 2.14 510 */ 511 public StringG overwriteLen(size_t pos, string val, ptrdiff_t len) 512 { 513 auto __p = g_string_overwrite_len(gString, pos, Str.toStringz(val), len); 514 515 if(__p is null) 516 { 517 return null; 518 } 519 520 return new StringG(cast(GString*) __p); 521 } 522 523 /** 524 * Adds a string on to the start of a #GString, 525 * expanding it if necessary. 526 * 527 * Params: 528 * val = the string to prepend on the start of @string 529 * 530 * Returns: @string 531 */ 532 public StringG prepend(string val) 533 { 534 auto __p = g_string_prepend(gString, Str.toStringz(val)); 535 536 if(__p is null) 537 { 538 return null; 539 } 540 541 return new StringG(cast(GString*) __p); 542 } 543 544 /** 545 * Adds a byte onto the start of a #GString, 546 * expanding it if necessary. 547 * 548 * Params: 549 * c = the byte to prepend on the start of the #GString 550 * 551 * Returns: @string 552 */ 553 public StringG prependC(char c) 554 { 555 auto __p = g_string_prepend_c(gString, c); 556 557 if(__p is null) 558 { 559 return null; 560 } 561 562 return new StringG(cast(GString*) __p); 563 } 564 565 /** 566 * Prepends @len bytes of @val to @string. 567 * 568 * If @len is positive, @val may contain embedded nuls and need 569 * not be nul-terminated. It is the caller's responsibility to 570 * ensure that @val has at least @len addressable bytes. 571 * 572 * If @len is negative, @val must be nul-terminated and @len 573 * is considered to request the entire string length. This 574 * makes g_string_prepend_len() equivalent to g_string_prepend(). 575 * 576 * Params: 577 * val = bytes to prepend 578 * len = number of bytes in @val to prepend, or -1 for all of @val 579 * 580 * Returns: @string 581 */ 582 public StringG prependLen(string val, ptrdiff_t len) 583 { 584 auto __p = g_string_prepend_len(gString, Str.toStringz(val), len); 585 586 if(__p is null) 587 { 588 return null; 589 } 590 591 return new StringG(cast(GString*) __p); 592 } 593 594 /** 595 * Converts a Unicode character into UTF-8, and prepends it 596 * to the string. 597 * 598 * Params: 599 * wc = a Unicode character 600 * 601 * Returns: @string 602 */ 603 public StringG prependUnichar(dchar wc) 604 { 605 auto __p = g_string_prepend_unichar(gString, wc); 606 607 if(__p is null) 608 { 609 return null; 610 } 611 612 return new StringG(cast(GString*) __p); 613 } 614 615 /** 616 * Replaces the string @find with the string @replace in a #GString up to 617 * @limit times. If the number of instances of @find in the #GString is 618 * less than @limit, all instances are replaced. If the number of 619 * instances is `0`, all instances of @find are replaced. 620 * 621 * Params: 622 * find = the string to find in @string 623 * replace = the string to insert in place of @find 624 * limit = the maximum instances of @find to replace with @replace, or `0` for 625 * no limit 626 * 627 * Returns: the number of find and replace operations performed. 628 * 629 * Since: 2.68 630 */ 631 public uint replace(string find, string replace, uint limit) 632 { 633 return g_string_replace(gString, Str.toStringz(find), Str.toStringz(replace), limit); 634 } 635 636 /** 637 * Sets the length of a #GString. If the length is less than 638 * the current length, the string will be truncated. If the 639 * length is greater than the current length, the contents 640 * of the newly added area are undefined. (However, as 641 * always, string->str[string->len] will be a nul byte.) 642 * 643 * Params: 644 * len = the new length 645 * 646 * Returns: @string 647 */ 648 public StringG setSize(size_t len) 649 { 650 auto __p = g_string_set_size(gString, len); 651 652 if(__p is null) 653 { 654 return null; 655 } 656 657 return new StringG(cast(GString*) __p); 658 } 659 660 /** 661 * Cuts off the end of the GString, leaving the first @len bytes. 662 * 663 * Params: 664 * len = the new size of @string 665 * 666 * Returns: @string 667 */ 668 public StringG truncate(size_t len) 669 { 670 auto __p = g_string_truncate(gString, len); 671 672 if(__p is null) 673 { 674 return null; 675 } 676 677 return new StringG(cast(GString*) __p); 678 } 679 680 /** 681 * Converts a #GString to uppercase. 682 * 683 * Deprecated: This function uses the locale-specific 684 * toupper() function, which is almost never the right thing. 685 * Use g_string_ascii_up() or g_utf8_strup() instead. 686 * 687 * Returns: @string 688 */ 689 public StringG up() 690 { 691 auto __p = g_string_up(gString); 692 693 if(__p is null) 694 { 695 return null; 696 } 697 698 return new StringG(cast(GString*) __p); 699 } 700 701 /** 702 * Writes a formatted string into a #GString. 703 * This function is similar to g_string_printf() except that 704 * the arguments to the format string are passed as a va_list. 705 * 706 * Params: 707 * format = the string format. See the printf() documentation 708 * args = the parameters to insert into the format string 709 * 710 * Since: 2.14 711 */ 712 public void vprintf(string format, void* args) 713 { 714 g_string_vprintf(gString, Str.toStringz(format), args); 715 } 716 717 /** 718 * Creates a new #GString, initialized with the given string. 719 * 720 * Params: 721 * init = the initial text to copy into the string, or %NULL to 722 * start with an empty string 723 * 724 * Returns: the new #GString 725 */ 726 public static StringG stringNew(string init) 727 { 728 auto __p = g_string_new(Str.toStringz(init)); 729 730 if(__p is null) 731 { 732 return null; 733 } 734 735 return new StringG(cast(GString*) __p, true); 736 } 737 738 /** 739 * Creates a new #GString with @len bytes of the @init buffer. 740 * Because a length is provided, @init need not be nul-terminated, 741 * and can contain embedded nul bytes. 742 * 743 * Since this function does not stop at nul bytes, it is the caller's 744 * responsibility to ensure that @init has at least @len addressable 745 * bytes. 746 * 747 * Params: 748 * init = initial contents of the string 749 * len = length of @init to use 750 * 751 * Returns: a new #GString 752 */ 753 public static StringG stringNewLen(string init, ptrdiff_t len) 754 { 755 auto __p = g_string_new_len(Str.toStringz(init), len); 756 757 if(__p is null) 758 { 759 return null; 760 } 761 762 return new StringG(cast(GString*) __p, true); 763 } 764 765 /** 766 * Creates a new #GString, with enough space for @dfl_size 767 * bytes. This is useful if you are going to add a lot of 768 * text to the string and don't want it to be reallocated 769 * too often. 770 * 771 * Params: 772 * dflSize = the default size of the space allocated to 773 * hold the string 774 * 775 * Returns: the new #GString 776 */ 777 public static StringG stringSizedNew(size_t dflSize) 778 { 779 auto __p = g_string_sized_new(dflSize); 780 781 if(__p is null) 782 { 783 return null; 784 } 785 786 return new StringG(cast(GString*) __p, true); 787 } 788 }