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