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