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 * Conversion parameters: 26 * inFile = glib-Strings.html 27 * outPack = glib 28 * outFile = StringG 29 * strct = GString 30 * realStrct= 31 * ctorStrct= 32 * clss = StringG 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_string_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - g_string_new 45 * - g_string_append 46 * - g_string_prepend 47 * - g_string_insert 48 * - g_string_overwrite 49 * omit signals: 50 * imports: 51 * - glib.Str 52 * - glib.Bytes 53 * structWrap: 54 * - GBytes* -> Bytes 55 * - GString* -> StringG 56 * module aliases: 57 * local aliases: 58 * - appendLen -> append 59 * - insertLen -> insert 60 * - overwriteLen -> overwrite 61 * - prependLen -> prepend 62 * overrides: 63 */ 64 65 module glib.StringG; 66 67 public import gtkc.glibtypes; 68 69 private import gtkc.glib; 70 private import glib.ConstructionException; 71 72 private import glib.Str; 73 private import glib.Bytes; 74 75 76 77 /** 78 * A GString is an object that handles the memory management of a C 79 * string for you. The emphasis of GString is on text, typically 80 * UTF-8. Crucially, the "str" member of a GString is guaranteed to 81 * have a trailing nul character, and it is therefore always safe to 82 * call functions such as strchr() or g_strdup() on it. 83 * 84 * However, a GString can also hold arbitrary binary data, because it 85 * has a "len" member, which includes any possible embedded nul 86 * characters in the data. Conceptually then, GString is like a 87 * GByteArray with the addition of many convenience methods for text, 88 * and a guaranteed nul terminator. 89 */ 90 public class StringG 91 { 92 93 /** the main Gtk struct */ 94 protected GString* gString; 95 96 97 /** Get the main Gtk struct */ 98 public GString* getStringGStruct() 99 { 100 return gString; 101 } 102 103 104 /** the main Gtk struct as a void* */ 105 protected void* getStruct() 106 { 107 return cast(void*)gString; 108 } 109 110 /** 111 * Sets our main struct and passes it to the parent class 112 */ 113 public this (GString* gString) 114 { 115 this.gString = gString; 116 } 117 118 /** 119 */ 120 121 /** 122 * Creates a new GString with len bytes of the init buffer. 123 * Because a length is provided, init need not be nul-terminated, 124 * and can contain embedded nul bytes. 125 * Since this function does not stop at nul bytes, it is the caller's 126 * responsibility to ensure that init has at least len addressable 127 * bytes. 128 * Params: 129 * init = initial contents of the string 130 * Throws: ConstructionException GTK+ fails to create the object. 131 */ 132 public this (string init) 133 { 134 // GString * g_string_new_len (const gchar *init, gssize len); 135 auto p = g_string_new_len(cast(char*)init.ptr, cast(int) init.length); 136 if(p is null) 137 { 138 throw new ConstructionException("null returned by g_string_new_len(cast(char*)init.ptr, cast(int) init.length)"); 139 } 140 this(cast(GString*) p); 141 } 142 143 /** 144 * Creates a new GString, with enough space for dfl_size 145 * bytes. This is useful if you are going to add a lot of 146 * text to the string and don't want it to be reallocated 147 * too often. 148 * Params: 149 * dflSize = the default size of the space allocated to 150 * hold the string 151 * Returns: the new GString 152 */ 153 public static StringG sizedNew(gsize dflSize) 154 { 155 // GString * g_string_sized_new (gsize dfl_size); 156 auto p = g_string_sized_new(dflSize); 157 158 if(p is null) 159 { 160 return null; 161 } 162 163 return new StringG(cast(GString*) p); 164 } 165 166 /** 167 * Copies the bytes from a string into a GString, 168 * destroying any previous contents. It is rather like 169 * the standard strcpy() function, except that you do not 170 * have to worry about having enough space to copy the string. 171 * Params: 172 * string = the destination GString. Its current contents 173 * are destroyed. 174 * rval = the string to copy into string 175 * Returns: string 176 */ 177 public StringG assign(string rval) 178 { 179 // GString * g_string_assign (GString *string, const gchar *rval); 180 auto p = g_string_assign(gString, Str.toStringz(rval)); 181 182 if(p is null) 183 { 184 return null; 185 } 186 187 return new StringG(cast(GString*) p); 188 } 189 190 /** 191 * Writes a formatted string into a GString. 192 * This function is similar to g_string_printf() except that 193 * the arguments to the format string are passed as a va_list. 194 * Since 2.14 195 * Params: 196 * string = a GString 197 * format = the string format. See the printf() documentation 198 * args = the parameters to insert into the format string 199 */ 200 public void vprintf(string format, void* args) 201 { 202 // void g_string_vprintf (GString *string, const gchar *format, va_list args); 203 g_string_vprintf(gString, Str.toStringz(format), args); 204 } 205 206 /** 207 * Appends a formatted string onto the end of a GString. 208 * This function is similar to g_string_append_printf() 209 * except that the arguments to the format string are passed 210 * as a va_list. 211 * Since 2.14 212 * Params: 213 * string = a GString 214 * format = the string format. See the printf() documentation 215 * args = the list of arguments to insert in the output 216 */ 217 public void appendVprintf(string format, void* args) 218 { 219 // void g_string_append_vprintf (GString *string, const gchar *format, va_list args); 220 g_string_append_vprintf(gString, Str.toStringz(format), args); 221 } 222 223 /** 224 * Adds a byte onto the end of a GString, expanding 225 * it if necessary. 226 * Params: 227 * c = the byte to append onto the end of string 228 * Returns: string 229 */ 230 public StringG appendC(char c) 231 { 232 // GString * g_string_append_c (GString *string, gchar c); 233 auto p = g_string_append_c(gString, c); 234 235 if(p is null) 236 { 237 return null; 238 } 239 240 return new StringG(cast(GString*) p); 241 } 242 243 /** 244 * Converts a Unicode character into UTF-8, and appends it 245 * to the string. 246 * Params: 247 * wc = a Unicode character 248 * Returns: string 249 */ 250 public StringG appendUnichar(gunichar wc) 251 { 252 // GString * g_string_append_unichar (GString *string, gunichar wc); 253 auto p = g_string_append_unichar(gString, wc); 254 255 if(p is null) 256 { 257 return null; 258 } 259 260 return new StringG(cast(GString*) p); 261 } 262 263 /** 264 * Appends len bytes of val to string. Because len is 265 * provided, val may contain embedded nuls and need not 266 * be nul-terminated. 267 * Since this function does not stop at nul bytes, it is 268 * the caller's responsibility to ensure that val has at 269 * least len addressable bytes. 270 * Params: 271 * string = a GString 272 * val = bytes to append 273 * Returns: string 274 */ 275 public StringG append(string val) 276 { 277 // GString * g_string_append_len (GString *string, const gchar *val, gssize len); 278 auto p = g_string_append_len(gString, cast(char*)val.ptr, cast(int) val.length); 279 280 if(p is null) 281 { 282 return null; 283 } 284 285 return new StringG(cast(GString*) p); 286 } 287 288 /** 289 * Appends unescaped to string, escaped any characters that 290 * are reserved in URIs using URI-style escape sequences. 291 * Since 2.16 292 * Params: 293 * string = a GString 294 * unescaped = a string 295 * reservedCharsAllowed = a string of reserved characters allowed 296 * to be used, or NULL 297 * allowUtf8 = set TRUE if the escaped string may include UTF8 characters 298 * Returns: string 299 */ 300 public StringG appendUriEscaped(string unescaped, string reservedCharsAllowed, int allowUtf8) 301 { 302 // GString * g_string_append_uri_escaped (GString *string, const gchar *unescaped, const gchar *reserved_chars_allowed, gboolean allow_utf8); 303 auto p = g_string_append_uri_escaped(gString, Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8); 304 305 if(p is null) 306 { 307 return null; 308 } 309 310 return new StringG(cast(GString*) p); 311 } 312 313 /** 314 * Adds a byte onto the start of a GString, 315 * expanding it if necessary. 316 * Params: 317 * c = the byte to prepend on the start of the GString 318 * Returns: string 319 */ 320 public StringG prependC(char c) 321 { 322 // GString * g_string_prepend_c (GString *string, gchar c); 323 auto p = g_string_prepend_c(gString, c); 324 325 if(p is null) 326 { 327 return null; 328 } 329 330 return new StringG(cast(GString*) p); 331 } 332 333 /** 334 * Converts a Unicode character into UTF-8, and prepends it 335 * to the string. 336 * Params: 337 * wc = a Unicode character 338 * Returns: string 339 */ 340 public StringG prependUnichar(gunichar wc) 341 { 342 // GString * g_string_prepend_unichar (GString *string, gunichar wc); 343 auto p = g_string_prepend_unichar(gString, wc); 344 345 if(p is null) 346 { 347 return null; 348 } 349 350 return new StringG(cast(GString*) p); 351 } 352 353 /** 354 * Prepends len bytes of val to string. 355 * Because len is provided, val may contain 356 * embedded nuls and need not be nul-terminated. 357 * Since this function does not stop at nul bytes, 358 * it is the caller's responsibility to ensure that 359 * val has at least len addressable bytes. 360 * Params: 361 * string = a GString 362 * val = bytes to prepend 363 * Returns: string 364 */ 365 public StringG prepend(string val) 366 { 367 // GString * g_string_prepend_len (GString *string, const gchar *val, gssize len); 368 auto p = g_string_prepend_len(gString, cast(char*)val.ptr, cast(int) val.length); 369 370 if(p is null) 371 { 372 return null; 373 } 374 375 return new StringG(cast(GString*) p); 376 } 377 378 /** 379 * Inserts a byte into a GString, expanding it if necessary. 380 * Params: 381 * pos = the position to insert the byte 382 * c = the byte to insert 383 * Returns: string 384 */ 385 public StringG insertC(gssize pos, char c) 386 { 387 // GString * g_string_insert_c (GString *string, gssize pos, gchar c); 388 auto p = g_string_insert_c(gString, pos, c); 389 390 if(p is null) 391 { 392 return null; 393 } 394 395 return new StringG(cast(GString*) p); 396 } 397 398 /** 399 * Converts a Unicode character into UTF-8, and insert it 400 * into the string at the given position. 401 * Params: 402 * pos = the position at which to insert character, or -1 403 * to append at the end of the string 404 * wc = a Unicode character 405 * Returns: string 406 */ 407 public StringG insertUnichar(gssize pos, gunichar wc) 408 { 409 // GString * g_string_insert_unichar (GString *string, gssize pos, gunichar wc); 410 auto p = g_string_insert_unichar(gString, pos, wc); 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 * Because len is provided, val may contain embedded 423 * nuls and need not be nul-terminated. If pos is -1, 424 * bytes are inserted at the end of the string. 425 * Since this function does not stop at nul bytes, it is 426 * the caller's responsibility to ensure that val has at 427 * least len addressable bytes. 428 * Params: 429 * string = a GString 430 * pos = position in string where insertion should 431 * happen, or -1 for at the end 432 * val = bytes to insert 433 * Returns: string 434 */ 435 public StringG insert(gssize pos, string val) 436 { 437 // GString * g_string_insert_len (GString *string, gssize pos, const gchar *val, gssize len); 438 auto p = g_string_insert_len(gString, pos, cast(char*)val.ptr, cast(int) val.length); 439 440 if(p is null) 441 { 442 return null; 443 } 444 445 return new StringG(cast(GString*) p); 446 } 447 448 /** 449 * Overwrites part of a string, lengthening it if necessary. 450 * This function will work with embedded nuls. 451 * Since 2.14 452 * Params: 453 * string = a GString 454 * pos = the position at which to start overwriting 455 * val = the string that will overwrite the string starting at pos 456 * Returns: string 457 */ 458 public StringG overwrite(gsize pos, string val) 459 { 460 // GString * g_string_overwrite_len (GString *string, gsize pos, const gchar *val, gssize len); 461 auto p = g_string_overwrite_len(gString, pos, cast(char*)val.ptr, cast(int) val.length); 462 463 if(p is null) 464 { 465 return null; 466 } 467 468 return new StringG(cast(GString*) p); 469 } 470 471 /** 472 * Removes len bytes from a GString, starting at position pos. 473 * The rest of the GString is shifted down to fill the gap. 474 * Params: 475 * pos = the position of the content to remove 476 * len = the number of bytes to remove, or -1 to remove all 477 * following bytes 478 * Returns: string 479 */ 480 public StringG erase(gssize pos, gssize len) 481 { 482 // GString * g_string_erase (GString *string, gssize pos, gssize len); 483 auto p = g_string_erase(gString, pos, len); 484 485 if(p is null) 486 { 487 return null; 488 } 489 490 return new StringG(cast(GString*) p); 491 } 492 493 /** 494 * Cuts off the end of the GString, leaving the first len bytes. 495 * Params: 496 * len = the new size of string 497 * Returns: string 498 */ 499 public StringG truncate(gsize len) 500 { 501 // GString * g_string_truncate (GString *string, gsize len); 502 auto p = g_string_truncate(gString, len); 503 504 if(p is null) 505 { 506 return null; 507 } 508 509 return new StringG(cast(GString*) p); 510 } 511 512 /** 513 * Sets the length of a GString. If the length is less than 514 * the current length, the string will be truncated. If the 515 * length is greater than the current length, the contents 516 * of the newly added area are undefined. (However, as 517 * always, string->str[string->len] will be a nul byte.) 518 * Params: 519 * len = the new length 520 * Returns: string 521 */ 522 public StringG setSize(gsize len) 523 { 524 // GString * g_string_set_size (GString *string, gsize len); 525 auto p = g_string_set_size(gString, len); 526 527 if(p is null) 528 { 529 return null; 530 } 531 532 return new StringG(cast(GString*) p); 533 } 534 535 /** 536 * Frees the memory allocated for the GString. 537 * If free_segment is TRUE it also frees the character data. If 538 * it's FALSE, the caller gains ownership of the buffer and must 539 * free it after use with g_free(). 540 * Params: 541 * string = a GString 542 * freeSegment = if TRUE, the actual character data is freed as well 543 * Returns: the character data of string (i.e. NULL if free_segment is TRUE) 544 */ 545 public string free(int freeSegment) 546 { 547 // gchar * g_string_free (GString *string, gboolean free_segment); 548 return Str.toString(g_string_free(gString, freeSegment)); 549 } 550 551 /** 552 * Transfers ownership of the contents of string to a newly allocated 553 * GBytes. The GString structure itself is deallocated, and it is 554 * therefore invalid to use string after invoking this function. 555 * Note that while GString ensures that its buffer always has a 556 * trailing nul character (not reflected in its "len"), the returned 557 * GBytes does not include this extra nul; i.e. it has length exactly 558 * equal to the "len" member. 559 * Since 2.34 560 * Returns: A newly allocated GBytes containing contents of string; string itself is freed 561 */ 562 public Bytes freeToBytes() 563 { 564 // GBytes * g_string_free_to_bytes (GString *string); 565 auto p = g_string_free_to_bytes(gString); 566 567 if(p is null) 568 { 569 return null; 570 } 571 572 return new Bytes(cast(GBytes*) p); 573 } 574 575 /** 576 * Warning 577 * g_string_up has been deprecated since version 2.2 and should not be used in newly-written code. This function uses the locale-specific 578 * toupper() function, which is almost never the right thing. 579 * Use g_string_ascii_up() or g_utf8_strup() instead. 580 * Converts a GString to uppercase. 581 * Returns: string 582 */ 583 public StringG up() 584 { 585 // GString * g_string_up (GString *string); 586 auto p = g_string_up(gString); 587 588 if(p is null) 589 { 590 return null; 591 } 592 593 return new StringG(cast(GString*) p); 594 } 595 596 /** 597 * Warning 598 * g_string_down has been deprecated since version 2.2 and should not be used in newly-written code. This function uses the locale-specific 599 * tolower() function, which is almost never the right thing. 600 * Use g_string_ascii_down() or g_utf8_strdown() instead. 601 * Converts a GString to lowercase. 602 * Returns: the GString 603 */ 604 public StringG down() 605 { 606 // GString * g_string_down (GString *string); 607 auto p = g_string_down(gString); 608 609 if(p is null) 610 { 611 return null; 612 } 613 614 return new StringG(cast(GString*) p); 615 } 616 617 /** 618 * Creates a hash code for str; for use with GHashTable. 619 * Returns: hash code for str 620 */ 621 public uint hash() 622 { 623 // guint g_string_hash (const GString *str); 624 return g_string_hash(gString); 625 } 626 627 /** 628 * Compares two strings for equality, returning TRUE if they are equal. 629 * For use with GHashTable. 630 * Params: 631 * v = a GString 632 * v2 = another GString 633 * Returns: TRUE if the strings are the same length and contain the same bytes 634 */ 635 public int equal(StringG v2) 636 { 637 // gboolean g_string_equal (const GString *v, const GString *v2); 638 return g_string_equal(gString, (v2 is null) ? null : v2.getStringGStruct()); 639 } 640 }