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