1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
40 #include "guriprivate.h"
42 #include "gutilsprivate.h"
48 * @short_description: text buffers which grow automatically
51 * A #GString is an object that handles the memory management of a C
52 * string for you. The emphasis of #GString is on text, typically
53 * UTF-8. Crucially, the "str" member of a #GString is guaranteed to
54 * have a trailing nul character, and it is therefore always safe to
55 * call functions such as strchr() or g_strdup() on it.
57 * However, a #GString can also hold arbitrary binary data, because it
58 * has a "len" member, which includes any possible embedded nul
59 * characters in the data. Conceptually then, #GString is like a
60 * #GByteArray with the addition of many convenience methods for text,
61 * and a guaranteed nul terminator.
66 * @str: points to the character data. It may move as text is added.
67 * The @str field is null-terminated and so
68 * can be used as an ordinary C string.
69 * @len: contains the length of the string, not including the
70 * terminating nul byte.
71 * @allocated_len: the number of bytes that can be stored in the
72 * string before it needs to be reallocated. May be larger than @len.
74 * The GString struct contains the public fields of a GString.
78 g_string_maybe_expand (GString *string,
81 /* Detect potential overflow */
82 if G_UNLIKELY ((G_MAXSIZE - string->len - 1) < len)
83 g_error ("adding %" G_GSIZE_FORMAT " to string would overflow", len);
85 if (string->len + len >= string->allocated_len)
87 string->allocated_len = g_nearest_pow (string->len + len + 1);
88 /* If the new size is bigger than G_MAXSIZE / 2, only allocate enough
89 * memory for this string and don't over-allocate. */
90 if (string->allocated_len == 0)
91 string->allocated_len = string->len + len + 1;
92 string->str = g_realloc (string->str, string->allocated_len);
97 * g_string_sized_new: (constructor)
98 * @dfl_size: the default size of the space allocated to hold the string
100 * Creates a new #GString, with enough space for @dfl_size
101 * bytes. This is useful if you are going to add a lot of
102 * text to the string and don't want it to be reallocated
105 * Returns: (transfer full): the new #GString
108 g_string_sized_new (gsize dfl_size)
110 GString *string = g_slice_new (GString);
112 string->allocated_len = 0;
116 g_string_maybe_expand (string, MAX (dfl_size, 64));
123 * g_string_new: (constructor)
124 * @init: (nullable): the initial text to copy into the string, or %NULL to
125 * start with an empty string
127 * Creates a new #GString, initialized with the given string.
129 * Returns: (transfer full): the new #GString
132 g_string_new (const gchar *init)
136 if (init == NULL || *init == '\0')
137 string = g_string_sized_new (2);
143 string = g_string_sized_new (len + 2);
145 g_string_append_len (string, init, len);
152 * g_string_new_len: (constructor)
153 * @init: initial contents of the string
154 * @len: length of @init to use
156 * Creates a new #GString with @len bytes of the @init buffer.
157 * Because a length is provided, @init need not be nul-terminated,
158 * and can contain embedded nul bytes.
160 * Since this function does not stop at nul bytes, it is the caller's
161 * responsibility to ensure that @init has at least @len addressable
164 * Returns: (transfer full): a new #GString
167 g_string_new_len (const gchar *init,
173 return g_string_new (init);
176 string = g_string_sized_new (len);
179 g_string_append_len (string, init, len);
187 * @string: (transfer full): a #GString
188 * @free_segment: if %TRUE, the actual character data is freed as well
190 * Frees the memory allocated for the #GString.
191 * If @free_segment is %TRUE it also frees the character data. If
192 * it's %FALSE, the caller gains ownership of the buffer and must
193 * free it after use with g_free().
195 * Returns: (nullable): the character data of @string
196 * (i.e. %NULL if @free_segment is %TRUE)
199 g_string_free (GString *string,
200 gboolean free_segment)
204 g_return_val_if_fail (string != NULL, NULL);
208 g_free (string->str);
212 segment = string->str;
214 g_slice_free (GString, string);
220 * g_string_free_to_bytes:
221 * @string: (transfer full): a #GString
223 * Transfers ownership of the contents of @string to a newly allocated
224 * #GBytes. The #GString structure itself is deallocated, and it is
225 * therefore invalid to use @string after invoking this function.
227 * Note that while #GString ensures that its buffer always has a
228 * trailing nul character (not reflected in its "len"), the returned
229 * #GBytes does not include this extra nul; i.e. it has length exactly
230 * equal to the "len" member.
232 * Returns: (transfer full): A newly allocated #GBytes containing contents of @string; @string itself is freed
236 g_string_free_to_bytes (GString *string)
241 g_return_val_if_fail (string != NULL, NULL);
245 buf = g_string_free (string, FALSE);
247 return g_bytes_new_take (buf, len);
253 * @v2: another #GString
255 * Compares two strings for equality, returning %TRUE if they are equal.
256 * For use with #GHashTable.
258 * Returns: %TRUE if the strings are the same length and contain the
262 g_string_equal (const GString *v,
266 GString *string1 = (GString *) v;
267 GString *string2 = (GString *) v2;
268 gsize i = string1->len;
270 if (i != string2->len)
288 * @str: a string to hash
290 * Creates a hash code for @str; for use with #GHashTable.
292 * Returns: hash code for @str
295 g_string_hash (const GString *str)
297 const gchar *p = str->str;
301 /* 31 bit hash function */
304 h = (h << 5) - h + *p;
313 * @string: the destination #GString. Its current contents
315 * @rval: the string to copy into @string
317 * Copies the bytes from a string into a #GString,
318 * destroying any previous contents. It is rather like
319 * the standard strcpy() function, except that you do not
320 * have to worry about having enough space to copy the string.
322 * Returns: (transfer none): @string
325 g_string_assign (GString *string,
328 g_return_val_if_fail (string != NULL, NULL);
329 g_return_val_if_fail (rval != NULL, string);
331 /* Make sure assigning to itself doesn't corrupt the string. */
332 if (string->str != rval)
334 /* Assigning from substring should be ok, since
335 * g_string_truncate() does not reallocate.
337 g_string_truncate (string, 0);
338 g_string_append (string, rval);
346 * @string: a #GString
347 * @len: the new size of @string
349 * Cuts off the end of the GString, leaving the first @len bytes.
351 * Returns: (transfer none): @string
354 g_string_truncate (GString *string,
357 g_return_val_if_fail (string != NULL, NULL);
359 string->len = MIN (len, string->len);
360 string->str[string->len] = 0;
367 * @string: a #GString
368 * @len: the new length
370 * Sets the length of a #GString. If the length is less than
371 * the current length, the string will be truncated. If the
372 * length is greater than the current length, the contents
373 * of the newly added area are undefined. (However, as
374 * always, string->str[string->len] will be a nul byte.)
376 * Returns: (transfer none): @string
379 g_string_set_size (GString *string,
382 g_return_val_if_fail (string != NULL, NULL);
384 if (len >= string->allocated_len)
385 g_string_maybe_expand (string, len - string->len);
388 string->str[len] = 0;
394 * g_string_insert_len:
395 * @string: a #GString
396 * @pos: position in @string where insertion should
397 * happen, or -1 for at the end
398 * @val: bytes to insert
399 * @len: number of bytes of @val to insert, or -1 for all of @val
401 * Inserts @len bytes of @val into @string at @pos.
403 * If @len is positive, @val may contain embedded nuls and need
404 * not be nul-terminated. It is the caller's responsibility to
405 * ensure that @val has at least @len addressable bytes.
407 * If @len is negative, @val must be nul-terminated and @len
408 * is considered to request the entire string length.
410 * If @pos is -1, bytes are inserted at the end of the string.
412 * Returns: (transfer none): @string
415 g_string_insert_len (GString *string,
420 gsize len_unsigned, pos_unsigned;
422 g_return_val_if_fail (string != NULL, NULL);
423 g_return_val_if_fail (len == 0 || val != NULL, string);
433 pos_unsigned = string->len;
437 g_return_val_if_fail (pos_unsigned <= string->len, string);
440 /* Check whether val represents a substring of string.
441 * This test probably violates chapter and verse of the C standards,
442 * since ">=" and "<=" are only valid when val really is a substring.
443 * In practice, it will work on modern archs.
445 if (G_UNLIKELY (val >= string->str && val <= string->str + string->len))
447 gsize offset = val - string->str;
450 g_string_maybe_expand (string, len_unsigned);
451 val = string->str + offset;
452 /* At this point, val is valid again. */
454 /* Open up space where we are going to insert. */
455 if (pos_unsigned < string->len)
456 memmove (string->str + pos_unsigned + len_unsigned,
457 string->str + pos_unsigned, string->len - pos_unsigned);
459 /* Move the source part before the gap, if any. */
460 if (offset < pos_unsigned)
462 precount = MIN (len_unsigned, pos_unsigned - offset);
463 memcpy (string->str + pos_unsigned, val, precount);
466 /* Move the source part after the gap, if any. */
467 if (len_unsigned > precount)
468 memcpy (string->str + pos_unsigned + precount,
469 val + /* Already moved: */ precount +
470 /* Space opened up: */ len_unsigned,
471 len_unsigned - precount);
475 g_string_maybe_expand (string, len_unsigned);
477 /* If we aren't appending at the end, move a hunk
478 * of the old string to the end, opening up space
480 if (pos_unsigned < string->len)
481 memmove (string->str + pos_unsigned + len_unsigned,
482 string->str + pos_unsigned, string->len - pos_unsigned);
484 /* insert the new string */
485 if (len_unsigned == 1)
486 string->str[pos_unsigned] = *val;
488 memcpy (string->str + pos_unsigned, val, len_unsigned);
491 string->len += len_unsigned;
493 string->str[string->len] = 0;
499 * g_string_append_uri_escaped:
500 * @string: a #GString
501 * @unescaped: a string
502 * @reserved_chars_allowed: a string of reserved characters allowed
503 * to be used, or %NULL
504 * @allow_utf8: set %TRUE if the escaped string may include UTF8 characters
506 * Appends @unescaped to @string, escaping any characters that
507 * are reserved in URIs using URI-style escape sequences.
509 * Returns: (transfer none): @string
514 g_string_append_uri_escaped (GString *string,
515 const gchar *unescaped,
516 const gchar *reserved_chars_allowed,
519 _uri_encoder (string, (const guchar *) unescaped, strlen (unescaped),
520 reserved_chars_allowed, allow_utf8);
526 * @string: a #GString
527 * @val: the string to append onto the end of @string
529 * Adds a string onto the end of a #GString, expanding
532 * Returns: (transfer none): @string
535 g_string_append (GString *string,
538 return g_string_insert_len (string, -1, val, -1);
542 * g_string_append_len:
543 * @string: a #GString
544 * @val: bytes to append
545 * @len: number of bytes of @val to use, or -1 for all of @val
547 * Appends @len bytes of @val to @string.
549 * If @len is positive, @val may contain embedded nuls and need
550 * not be nul-terminated. It is the caller's responsibility to
551 * ensure that @val has at least @len addressable bytes.
553 * If @len is negative, @val must be nul-terminated and @len
554 * is considered to request the entire string length. This
555 * makes g_string_append_len() equivalent to g_string_append().
557 * Returns: (transfer none): @string
560 g_string_append_len (GString *string,
564 return g_string_insert_len (string, -1, val, len);
569 * @string: a #GString
570 * @c: the byte to append onto the end of @string
572 * Adds a byte onto the end of a #GString, expanding
575 * Returns: (transfer none): @string
577 #undef g_string_append_c
579 g_string_append_c (GString *string,
582 g_return_val_if_fail (string != NULL, NULL);
584 return g_string_insert_c (string, -1, c);
588 * g_string_append_unichar:
589 * @string: a #GString
590 * @wc: a Unicode character
592 * Converts a Unicode character into UTF-8, and appends it
595 * Returns: (transfer none): @string
598 g_string_append_unichar (GString *string,
601 g_return_val_if_fail (string != NULL, NULL);
603 return g_string_insert_unichar (string, -1, wc);
608 * @string: a #GString
609 * @val: the string to prepend on the start of @string
611 * Adds a string on to the start of a #GString,
612 * expanding it if necessary.
614 * Returns: (transfer none): @string
617 g_string_prepend (GString *string,
620 return g_string_insert_len (string, 0, val, -1);
624 * g_string_prepend_len:
625 * @string: a #GString
626 * @val: bytes to prepend
627 * @len: number of bytes in @val to prepend, or -1 for all of @val
629 * Prepends @len bytes of @val to @string.
631 * If @len is positive, @val may contain embedded nuls and need
632 * not be nul-terminated. It is the caller's responsibility to
633 * ensure that @val has at least @len addressable bytes.
635 * If @len is negative, @val must be nul-terminated and @len
636 * is considered to request the entire string length. This
637 * makes g_string_prepend_len() equivalent to g_string_prepend().
639 * Returns: (transfer none): @string
642 g_string_prepend_len (GString *string,
646 return g_string_insert_len (string, 0, val, len);
650 * g_string_prepend_c:
651 * @string: a #GString
652 * @c: the byte to prepend on the start of the #GString
654 * Adds a byte onto the start of a #GString,
655 * expanding it if necessary.
657 * Returns: (transfer none): @string
660 g_string_prepend_c (GString *string,
663 g_return_val_if_fail (string != NULL, NULL);
665 return g_string_insert_c (string, 0, c);
669 * g_string_prepend_unichar:
670 * @string: a #GString
671 * @wc: a Unicode character
673 * Converts a Unicode character into UTF-8, and prepends it
676 * Returns: (transfer none): @string
679 g_string_prepend_unichar (GString *string,
682 g_return_val_if_fail (string != NULL, NULL);
684 return g_string_insert_unichar (string, 0, wc);
689 * @string: a #GString
690 * @pos: the position to insert the copy of the string
691 * @val: the string to insert
693 * Inserts a copy of a string into a #GString,
694 * expanding it if necessary.
696 * Returns: (transfer none): @string
699 g_string_insert (GString *string,
703 return g_string_insert_len (string, pos, val, -1);
708 * @string: a #GString
709 * @pos: the position to insert the byte
710 * @c: the byte to insert
712 * Inserts a byte into a #GString, expanding it if necessary.
714 * Returns: (transfer none): @string
717 g_string_insert_c (GString *string,
723 g_return_val_if_fail (string != NULL, NULL);
725 g_string_maybe_expand (string, 1);
730 g_return_val_if_fail ((gsize) pos <= string->len, string);
733 /* If not just an append, move the old stuff */
734 if (pos_unsigned < string->len)
735 memmove (string->str + pos_unsigned + 1,
736 string->str + pos_unsigned, string->len - pos_unsigned);
738 string->str[pos_unsigned] = c;
742 string->str[string->len] = 0;
748 * g_string_insert_unichar:
749 * @string: a #GString
750 * @pos: the position at which to insert character, or -1
751 * to append at the end of the string
752 * @wc: a Unicode character
754 * Converts a Unicode character into UTF-8, and insert it
755 * into the string at the given position.
757 * Returns: (transfer none): @string
760 g_string_insert_unichar (GString *string,
764 gint charlen, first, i;
767 g_return_val_if_fail (string != NULL, NULL);
769 /* Code copied from g_unichar_to_utf() */
780 else if (wc < 0x10000)
785 else if (wc < 0x200000)
790 else if (wc < 0x4000000)
800 /* End of copied code */
802 g_string_maybe_expand (string, charlen);
807 g_return_val_if_fail ((gsize) pos <= string->len, string);
809 /* If not just an append, move the old stuff */
810 if ((gsize) pos < string->len)
811 memmove (string->str + pos + charlen, string->str + pos, string->len - pos);
813 dest = string->str + pos;
814 /* Code copied from g_unichar_to_utf() */
815 for (i = charlen - 1; i > 0; --i)
817 dest[i] = (wc & 0x3f) | 0x80;
820 dest[0] = wc | first;
821 /* End of copied code */
823 string->len += charlen;
825 string->str[string->len] = 0;
831 * g_string_overwrite:
832 * @string: a #GString
833 * @pos: the position at which to start overwriting
834 * @val: the string that will overwrite the @string starting at @pos
836 * Overwrites part of a string, lengthening it if necessary.
838 * Returns: (transfer none): @string
843 g_string_overwrite (GString *string,
847 g_return_val_if_fail (val != NULL, string);
848 return g_string_overwrite_len (string, pos, val, strlen (val));
852 * g_string_overwrite_len:
853 * @string: a #GString
854 * @pos: the position at which to start overwriting
855 * @val: the string that will overwrite the @string starting at @pos
856 * @len: the number of bytes to write from @val
858 * Overwrites part of a string, lengthening it if necessary.
859 * This function will work with embedded nuls.
861 * Returns: (transfer none): @string
866 g_string_overwrite_len (GString *string,
873 g_return_val_if_fail (string != NULL, NULL);
878 g_return_val_if_fail (val != NULL, string);
879 g_return_val_if_fail (pos <= string->len, string);
886 if (end > string->len)
887 g_string_maybe_expand (string, end - string->len);
889 memcpy (string->str + pos, val, len);
891 if (end > string->len)
893 string->str[end] = '\0';
902 * @string: a #GString
903 * @pos: the position of the content to remove
904 * @len: the number of bytes to remove, or -1 to remove all
907 * Removes @len bytes from a #GString, starting at position @pos.
908 * The rest of the #GString is shifted down to fill the gap.
910 * Returns: (transfer none): @string
913 g_string_erase (GString *string,
917 gsize len_unsigned, pos_unsigned;
919 g_return_val_if_fail (string != NULL, NULL);
920 g_return_val_if_fail (pos >= 0, string);
923 g_return_val_if_fail (pos_unsigned <= string->len, string);
926 len_unsigned = string->len - pos_unsigned;
930 g_return_val_if_fail (pos_unsigned + len_unsigned <= string->len, string);
932 if (pos_unsigned + len_unsigned < string->len)
933 memmove (string->str + pos_unsigned,
934 string->str + pos_unsigned + len_unsigned,
935 string->len - (pos_unsigned + len_unsigned));
938 string->len -= len_unsigned;
940 string->str[string->len] = 0;
947 * @string: a #GString
948 * @find: the string to find in @string
949 * @replace: the string to insert in place of @find
950 * @limit: the maximum instances of @find to replace with @replace, or `0` for
953 * Replaces the string @find with the string @replace in a #GString up to
954 * @limit times. If the number of instances of @find in the #GString is
955 * less than @limit, all instances are replaced. If @limit is `0`,
956 * all instances of @find are replaced.
958 * If @find is the empty string, since versions 2.69.1 and 2.68.4 the
959 * replacement will be inserted no more than once per possible position
960 * (beginning of string, end of string and between characters). This did
961 * not work correctly in earlier versions.
963 * Returns: the number of find and replace operations performed.
968 g_string_replace (GString *string,
970 const gchar *replace,
973 gsize f_len, r_len, pos;
977 g_return_val_if_fail (string != NULL, 0);
978 g_return_val_if_fail (find != NULL, 0);
979 g_return_val_if_fail (replace != NULL, 0);
981 f_len = strlen (find);
982 r_len = strlen (replace);
985 while ((next = strstr (cur, find)) != NULL)
987 pos = next - string->str;
988 g_string_erase (string, pos, f_len);
989 g_string_insert (string, pos, replace);
990 cur = string->str + pos + r_len;
992 /* Only match the empty string once at any given position, to
993 * avoid infinite loops */
1009 * g_string_ascii_down:
1010 * @string: a GString
1012 * Converts all uppercase ASCII letters to lowercase ASCII letters.
1014 * Returns: (transfer none): passed-in @string pointer, with all the
1015 * uppercase characters converted to lowercase in place,
1016 * with semantics that exactly match g_ascii_tolower().
1019 g_string_ascii_down (GString *string)
1024 g_return_val_if_fail (string != NULL, NULL);
1031 *s = g_ascii_tolower (*s);
1040 * g_string_ascii_up:
1041 * @string: a GString
1043 * Converts all lowercase ASCII letters to uppercase ASCII letters.
1045 * Returns: (transfer none): passed-in @string pointer, with all the
1046 * lowercase characters converted to uppercase in place,
1047 * with semantics that exactly match g_ascii_toupper().
1050 g_string_ascii_up (GString *string)
1055 g_return_val_if_fail (string != NULL, NULL);
1062 *s = g_ascii_toupper (*s);
1072 * @string: a #GString
1074 * Converts a #GString to lowercase.
1076 * Returns: (transfer none): the #GString
1078 * Deprecated:2.2: This function uses the locale-specific
1079 * tolower() function, which is almost never the right thing.
1080 * Use g_string_ascii_down() or g_utf8_strdown() instead.
1083 g_string_down (GString *string)
1088 g_return_val_if_fail (string != NULL, NULL);
1091 s = (guchar *) string->str;
1106 * @string: a #GString
1108 * Converts a #GString to uppercase.
1110 * Returns: (transfer none): @string
1112 * Deprecated:2.2: This function uses the locale-specific
1113 * toupper() function, which is almost never the right thing.
1114 * Use g_string_ascii_up() or g_utf8_strup() instead.
1117 g_string_up (GString *string)
1122 g_return_val_if_fail (string != NULL, NULL);
1125 s = (guchar *) string->str;
1139 * g_string_append_vprintf:
1140 * @string: a #GString
1141 * @format: (not nullable): the string format. See the printf() documentation
1142 * @args: the list of arguments to insert in the output
1144 * Appends a formatted string onto the end of a #GString.
1145 * This function is similar to g_string_append_printf()
1146 * except that the arguments to the format string are passed
1152 g_string_append_vprintf (GString *string,
1153 const gchar *format,
1159 g_return_if_fail (string != NULL);
1160 g_return_if_fail (format != NULL);
1162 len = g_vasprintf (&buf, format, args);
1166 g_string_maybe_expand (string, len);
1167 memcpy (string->str + string->len, buf, len + 1);
1175 * @string: a #GString
1176 * @format: (not nullable): the string format. See the printf() documentation
1177 * @args: the parameters to insert into the format string
1179 * Writes a formatted string into a #GString.
1180 * This function is similar to g_string_printf() except that
1181 * the arguments to the format string are passed as a va_list.
1186 g_string_vprintf (GString *string,
1187 const gchar *format,
1190 g_string_truncate (string, 0);
1191 g_string_append_vprintf (string, format, args);
1196 * @string: a #GString
1197 * @format: the string format. See the sprintf() documentation
1198 * @...: the parameters to insert into the format string
1200 * Writes a formatted string into a #GString.
1201 * This is similar to the standard sprintf() function,
1202 * except that the #GString buffer automatically expands
1203 * to contain the results. The previous contents of the
1204 * #GString are destroyed.
1206 * Deprecated: This function has been renamed to g_string_printf().
1211 * @string: a #GString
1212 * @format: the string format. See the printf() documentation
1213 * @...: the parameters to insert into the format string
1215 * Writes a formatted string into a #GString.
1216 * This is similar to the standard sprintf() function,
1217 * except that the #GString buffer automatically expands
1218 * to contain the results. The previous contents of the
1219 * #GString are destroyed.
1222 g_string_printf (GString *string,
1223 const gchar *format,
1228 g_string_truncate (string, 0);
1230 va_start (args, format);
1231 g_string_append_vprintf (string, format, args);
1236 * g_string_sprintfa:
1237 * @string: a #GString
1238 * @format: the string format. See the sprintf() documentation
1239 * @...: the parameters to insert into the format string
1241 * Appends a formatted string onto the end of a #GString.
1242 * This function is similar to g_string_sprintf() except that
1243 * the text is appended to the #GString.
1245 * Deprecated: This function has been renamed to g_string_append_printf()
1249 * g_string_append_printf:
1250 * @string: a #GString
1251 * @format: the string format. See the printf() documentation
1252 * @...: the parameters to insert into the format string
1254 * Appends a formatted string onto the end of a #GString.
1255 * This function is similar to g_string_printf() except
1256 * that the text is appended to the #GString.
1259 g_string_append_printf (GString *string,
1260 const gchar *format,
1265 va_start (args, format);
1266 g_string_append_vprintf (string, format, args);