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