alternative to assert
[gtkD.git] / gtkD / src / glib / StringG.d
blobf7dbcadf770028a86204ba94d5ec31fe6fc486c5
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Strings.html
26 * outPack = glib
27 * outFile = StringG
28 * strct = GString
29 * realStrct=
30 * ctorStrct=
31 * clss = StringG
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_string_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Str
45 * structWrap:
46 * - GString* -> StringG
47 * module aliases:
48 * local aliases:
51 module glib.StringG;
53 version(noAssert)
55 version(Tango)
57 import tango.io.Stdout; // use the tango loging?
61 private import gtkc.glibtypes;
63 private import gtkc.glib;
66 private import glib.Str;
71 /**
72 * Description
73 * A GString is similar to a standard C string, except that it grows automatically
74 * as text is appended or inserted. Also, it stores the length of the string, so
75 * can be used for binary data with embedded nul bytes.
77 public class StringG
80 /** the main Gtk struct */
81 protected GString* gString;
84 public GString* getStringGStruct()
86 return gString;
90 /** the main Gtk struct as a void* */
91 protected void* getStruct()
93 return cast(void*)gString;
96 /**
97 * Sets our main struct and passes it to the parent class
99 public this (GString* gString)
101 version(noAssert)
103 if ( gString is null )
105 int zero = 0;
106 version(Tango)
108 Stdout("struct gString is null on constructor").newline;
110 else
112 printf("struct gString is null on constructor");
114 zero = zero / zero;
117 else
119 assert(gString !is null, "struct gString is null on constructor");
121 this.gString = gString;
129 * Creates a new GString, initialized with the given string.
130 * init:
131 * the initial text to copy into the string.
132 * Returns:
133 * the new GString.
135 public this (char[] init)
137 // GString* g_string_new (const gchar *init);
138 this(cast(GString*)g_string_new(Str.toStringz(init)) );
142 * Creates a new GString with len bytes of the
143 * init buffer. Because a length is provided, init
144 * need not be nul-terminated, and can contain embedded
145 * nul bytes.
146 * Since this function does not stop at nul bytes, it is the caller's
147 * responsibility to ensure that init has at least len addressable bytes.
148 * init:
149 * initial contents of string.
150 * len:
151 * length of init to use.
152 * Returns:
153 * a new GString.
155 public this (char[] init, int len)
157 // GString* g_string_new_len (const gchar *init, gssize len);
158 this(cast(GString*)g_string_new_len(Str.toStringz(init), len) );
162 * Creates a new GString, with enough space for dfl_size
163 * bytes. This is useful if you are going to add a lot of
164 * text to the string and don't want it to be reallocated
165 * too often.
166 * dfl_size:
167 * the default size of the space allocated to
168 * hold the string.
169 * Returns:
170 * the new GString.
172 public static StringG sizedNew(uint dflSize)
174 // GString* g_string_sized_new (gsize dfl_size);
175 return new StringG( g_string_sized_new(dflSize) );
179 * Copies the bytes from a string into a GString,
180 * destroying any previous contents. It is rather like
181 * the standard strcpy() function, except that you do not
182 * have to worry about having enough space to copy the string.
183 * string:
184 * the destination GString. Its current contents
185 * are destroyed.
186 * rval:
187 * the string to copy into string
188 * Returns:
189 * the destination GString.
191 public StringG assign(char[] rval)
193 // GString* g_string_assign (GString *string, const gchar *rval);
194 return new StringG( g_string_assign(gString, Str.toStringz(rval)) );
200 * Writes a formatted string into a GString.
201 * This is similar to the standard sprintf() function,
202 * except that the GString buffer automatically expands
203 * to contain the results. The previous contents of the
204 * GString are destroyed.
205 * string:
206 * a GString.
207 * format:
208 * the string format. See the printf() documentation.
209 * ...:
210 * the parameters to insert into the format string.
212 public void printf(char[] format, ... )
214 // void g_string_printf (GString *string, const gchar *format, ...);
215 g_string_printf(gString, Str.toStringz(format));
219 * Appends a formatted string onto the end of a GString.
220 * This function is is similar to g_string_printf() except
221 * that the text is appended to the GString.
222 * string:
223 * a GString.
224 * format:
225 * the string format. See the printf() documentation.
226 * ...:
227 * the parameters to insert into the format string.
229 public void appendPrintf(char[] format, ... )
231 // void g_string_append_printf (GString *string, const gchar *format, ...);
232 g_string_append_printf(gString, Str.toStringz(format));
236 * Adds a string onto the end of a GString, expanding it if necessary.
237 * string:
238 * a GString.
239 * val:
240 * the string to append onto the end of the GString.
241 * Returns:
242 * the GString.
244 public StringG append(char[] val)
246 // GString* g_string_append (GString *string, const gchar *val);
247 return new StringG( g_string_append(gString, Str.toStringz(val)) );
251 * Adds a byte onto the end of a GString, expanding it if necessary.
252 * string:
253 * a GString.
254 * c:
255 * the byte to append onto the end of the GString.
256 * Returns:
257 * the GString.
259 public StringG appendC(char c)
261 // GString* g_string_append_c (GString *string, gchar c);
262 return new StringG( g_string_append_c(gString, c) );
266 * Converts a Unicode character into UTF-8, and appends it
267 * to the string.
268 * string:
269 * a GString
270 * wc:
271 * a Unicode character
272 * Returns:
273 * string
275 public StringG appendUnichar(gunichar wc)
277 // GString* g_string_append_unichar (GString *string, gunichar wc);
278 return new StringG( g_string_append_unichar(gString, wc) );
282 * Appends len bytes of val to string.
283 * Because len is provided, val may contain
284 * embedded nuls and need not be nul-terminated.
285 * Since this function does not stop at nul bytes, it is the caller's
286 * responsibility to ensure that val has at least len addressable bytes.
287 * string:
288 * a GString
289 * val:
290 * bytes to append
291 * len:
292 * number of bytes of val to use.
293 * Returns:
294 * the GString
296 public StringG appendLen(char[] val, int len)
298 // GString* g_string_append_len (GString *string, const gchar *val, gssize len);
299 return new StringG( g_string_append_len(gString, Str.toStringz(val), len) );
303 * Adds a string on to the start of a GString,
304 * expanding it if necessary.
305 * string:
306 * a GString
307 * val:
308 * the string to prepend on the start of the GString
309 * Returns:
310 * the GString
312 public StringG prepend(char[] val)
314 // GString* g_string_prepend (GString *string, const gchar *val);
315 return new StringG( g_string_prepend(gString, Str.toStringz(val)) );
319 * Adds a byte onto the start of a GString,
320 * expanding it if necessary.
321 * string:
322 * a GString
323 * c:
324 * the byte to prepend on the start of the GString
325 * Returns:
326 * the GString
328 public StringG prependC(char c)
330 // GString* g_string_prepend_c (GString *string, gchar c);
331 return new StringG( g_string_prepend_c(gString, c) );
335 * Converts a Unicode character into UTF-8, and prepends it
336 * to the string.
337 * string:
338 * a GString.
339 * wc:
340 * a Unicode character.
341 * Returns:
342 * string.
344 public StringG prependUnichar(gunichar wc)
346 // GString* g_string_prepend_unichar (GString *string, gunichar wc);
347 return new StringG( g_string_prepend_unichar(gString, wc) );
351 * Prepends len bytes of val to string.
352 * Because len is provided, val may contain
353 * embedded nuls and need not be nul-terminated.
354 * Since this function does not stop at nul bytes, it is the caller's
355 * responsibility to ensure that val has at least len addressable bytes.
356 * string:
357 * a GString
358 * val:
359 * bytes to prepend
360 * len:
361 * number of bytes in val to prepend
362 * Returns:
363 * the GString passed in
365 public StringG prependLen(char[] val, int len)
367 // GString* g_string_prepend_len (GString *string, const gchar *val, gssize len);
368 return new StringG( g_string_prepend_len(gString, Str.toStringz(val), len) );
372 * Inserts a copy of a string into a GString,
373 * expanding it if necessary.
374 * string:
375 * a GString
376 * pos:
377 * the position to insert the copy of the string
378 * val:
379 * the string to insert
380 * Returns:
381 * the GString
383 public StringG insert(int pos, char[] val)
385 // GString* g_string_insert (GString *string, gssize pos, const gchar *val);
386 return new StringG( g_string_insert(gString, pos, Str.toStringz(val)) );
390 * Inserts a byte into a GString, expanding it if necessary.
391 * string:
392 * a GString
393 * pos:
394 * the position to insert the byte
395 * c:
396 * the byte to insert
397 * Returns:
398 * the GString
400 public StringG insertC(int pos, char c)
402 // GString* g_string_insert_c (GString *string, gssize pos, gchar c);
403 return new StringG( g_string_insert_c(gString, pos, c) );
407 * Converts a Unicode character into UTF-8, and insert it
408 * into the string at the given position.
409 * string:
410 * a GString
411 * pos:
412 * the position at which to insert character, or -1 to
413 * append at the end of the string.
414 * wc:
415 * a Unicode character
416 * Returns:
417 * string
419 public StringG insertUnichar(int pos, gunichar wc)
421 // GString* g_string_insert_unichar (GString *string, gssize pos, gunichar wc);
422 return new StringG( g_string_insert_unichar(gString, pos, wc) );
426 * Inserts len bytes of val into string at pos.
427 * Because len is provided, val may contain embedded
428 * nuls and need not be nul-terminated. If pos is -1,
429 * bytes are inserted at the end of the string.
430 * Since this function does not stop at nul bytes, it is the caller's
431 * responsibility to ensure that val has at least len addressable bytes.
432 * string:
433 * a GString
434 * pos:
435 * position in string where insertion should
436 * happen, or -1 for at the end
437 * val:
438 * bytes to insert
439 * len:
440 * number of bytes of val to insert
441 * Returns:
442 * the GString
444 public StringG insertLen(int pos, char[] val, int len)
446 // GString* g_string_insert_len (GString *string, gssize pos, const gchar *val, gssize len);
447 return new StringG( g_string_insert_len(gString, pos, Str.toStringz(val), len) );
451 * Removes len bytes from a GString, starting at position pos.
452 * The rest of the GString is shifted down to fill the gap.
453 * string:
454 * a GString
455 * pos:
456 * the position of the content to remove
457 * len:
458 * the number of bytes to remove, or -1 to remove all
459 * following bytes
460 * Returns:
461 * the GString
463 public StringG erase(int pos, int len)
465 // GString* g_string_erase (GString *string, gssize pos, gssize len);
466 return new StringG( g_string_erase(gString, pos, len) );
470 * Cuts off the end of the GString, leaving the first len bytes.
471 * string:
472 * a GString
473 * len:
474 * the new size of the GString
475 * Returns:
476 * the GString
478 public StringG truncate(uint len)
480 // GString* g_string_truncate (GString *string, gsize len);
481 return new StringG( g_string_truncate(gString, len) );
485 * Sets the length of a GString. If the length is less than
486 * the current length, the string will be truncated. If the
487 * length is greater than the current length, the contents
488 * of the newly added area are undefined. (However, as
489 * always, string->str[string->len] will be a nul byte.)
490 * string:
491 * a GString
492 * len:
493 * the new length
494 * Returns:
495 * string
497 public StringG setSize(uint len)
499 // GString* g_string_set_size (GString *string, gsize len);
500 return new StringG( g_string_set_size(gString, len) );
504 * Frees the memory allocated for the GString.
505 * If free_segment is TRUE it also frees the character data.
506 * string:
507 * a GString
508 * free_segment:
509 * if TRUE the actual character data is freed as well
510 * Returns:
511 * the character data of string
512 * (i.e. NULL if free_segment is TRUE)
514 public char[] free(int freeSegment)
516 // gchar* g_string_free (GString *string, gboolean free_segment);
517 return Str.toString(g_string_free(gString, freeSegment) );
521 * Warning
522 * 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 toupper() function,
523 * which is almost never the right thing. Use g_string_ascii_up() or
524 * g_utf8_strup() instead.
525 * Converts a GString to uppercase.
526 * string:
527 * a GString
528 * Returns:
529 * the GString
531 public StringG up()
533 // GString* g_string_up (GString *string);
534 return new StringG( g_string_up(gString) );
538 * Warning
539 * 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 tolower() function,
540 * which is almost never the right thing. Use g_string_ascii_down() or
541 * g_utf8_strdown() instead.
542 * Converts a GString to lowercase.
543 * string:
544 * a GString
545 * Returns:
546 * the GString.
548 public StringG down()
550 // GString* g_string_down (GString *string);
551 return new StringG( g_string_down(gString) );
555 * Creates a hash code for str; for use with GHashTable.
556 * str:
557 * a string to hash
558 * Returns:
559 * hash code for str
561 public uint hash()
563 // guint g_string_hash (const GString *str);
564 return g_string_hash(gString);
568 * Compares two strings for equality, returning TRUE if they are equal.
569 * For use with GHashTable.
570 * Compares two strings for equality, returning TRUE if they are equal.
571 * For use with GHashTable.
572 * v:
573 * a GString
574 * v2:
575 * another GString
576 * Returns:
577 * TRUE if they strings are the same
578 * length and contain the same bytes.
580 public int equal(StringG v2)
582 // gboolean g_string_equal (const GString *v, const GString *v2);
583 return g_string_equal(gString, (v2 is null) ? null : v2.getStringGStruct());