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