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