1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
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/.
49 GHashTable *const_table;
62 * @v2: a key to compare with @v1
64 * Compares two strings for byte-by-byte equality and returns %TRUE
65 * if they are equal. It can be passed to g_hash_table_new() as the
66 * @key_equal_func parameter, when using strings as keys in a #GHashTable.
68 * Note that this function is primarily meant as a hash table comparison
69 * function. For a general-purpose, %NULL-safe string comparison function,
72 * Returns: %TRUE if the two keys match
75 g_str_equal (gconstpointer v1,
78 const gchar *string1 = v1;
79 const gchar *string2 = v2;
81 return strcmp (string1, string2) == 0;
88 * Converts a string to a hash value.
89 * It can be passed to g_hash_table_new() as the @hash_func
90 * parameter, when using strings as keys in a #GHashTable.
92 * Returns: a hash value corresponding to the key
95 g_str_hash (gconstpointer v)
97 /* 31 bit hash function */
98 const signed char *p = v;
102 for (p += 1; *p != '\0'; p++)
103 h = (h << 5) - h + *p;
108 #define MY_MAXSIZE ((gsize)-1)
111 nearest_power (gsize base, gsize num)
113 if (num > MY_MAXSIZE / 2)
132 * g_string_chunk_new:
133 * @size: the default size of the blocks of memory which are
134 * allocated to store the strings. If a particular string
135 * is larger than this default size, a larger block of
136 * memory will be allocated for it.
138 * Creates a new #GStringChunk.
140 * Returns: a new #GStringChunk
143 g_string_chunk_new (gsize size)
145 GStringChunk *new_chunk = g_new (GStringChunk, 1);
146 gsize actual_size = 1;
148 actual_size = nearest_power (1, size);
150 new_chunk->const_table = NULL;
151 new_chunk->storage_list = NULL;
152 new_chunk->storage_next = actual_size;
153 new_chunk->default_size = actual_size;
154 new_chunk->this_size = actual_size;
160 * g_string_chunk_free:
161 * @chunk: a #GStringChunk
163 * Frees all memory allocated by the #GStringChunk.
164 * After calling g_string_chunk_free() it is not safe to
165 * access any of the strings which were contained within it.
168 g_string_chunk_free (GStringChunk *chunk)
172 g_return_if_fail (chunk != NULL);
174 if (chunk->storage_list)
176 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
177 g_free (tmp_list->data);
179 g_slist_free (chunk->storage_list);
182 if (chunk->const_table)
183 g_hash_table_destroy (chunk->const_table);
189 * g_string_chunk_clear:
190 * @chunk: a #GStringChunk
192 * Frees all strings contained within the #GStringChunk.
193 * After calling g_string_chunk_clear() it is not safe to
194 * access any of the strings which were contained within it.
199 g_string_chunk_clear (GStringChunk *chunk)
203 g_return_if_fail (chunk != NULL);
205 if (chunk->storage_list)
207 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
208 g_free (tmp_list->data);
210 g_slist_free (chunk->storage_list);
212 chunk->storage_list = NULL;
213 chunk->storage_next = chunk->default_size;
214 chunk->this_size = chunk->default_size;
217 if (chunk->const_table)
218 g_hash_table_remove_all (chunk->const_table);
222 * g_string_chunk_insert:
223 * @chunk: a #GStringChunk
224 * @string: the string to add
226 * Adds a copy of @string to the #GStringChunk.
227 * It returns a pointer to the new copy of the string
228 * in the #GStringChunk. The characters in the string
229 * can be changed, if necessary, though you should not
230 * change anything after the end of the string.
232 * Unlike g_string_chunk_insert_const(), this function
233 * does not check for duplicates. Also strings added
234 * with g_string_chunk_insert() will not be searched
235 * by g_string_chunk_insert_const() when looking for
238 * Returns: a pointer to the copy of @string within
242 g_string_chunk_insert (GStringChunk *chunk,
245 g_return_val_if_fail (chunk != NULL, NULL);
247 return g_string_chunk_insert_len (chunk, string, -1);
251 * g_string_chunk_insert_const:
252 * @chunk: a #GStringChunk
253 * @string: the string to add
255 * Adds a copy of @string to the #GStringChunk, unless the same
256 * string has already been added to the #GStringChunk with
257 * g_string_chunk_insert_const().
259 * This function is useful if you need to copy a large number
260 * of strings but do not want to waste space storing duplicates.
261 * But you must remember that there may be several pointers to
262 * the same string, and so any changes made to the strings
263 * should be done very carefully.
265 * Note that g_string_chunk_insert_const() will not return a
266 * pointer to a string added with g_string_chunk_insert(), even
269 * Returns: a pointer to the new or existing copy of @string
270 * within the #GStringChunk
273 g_string_chunk_insert_const (GStringChunk *chunk,
278 g_return_val_if_fail (chunk != NULL, NULL);
280 if (!chunk->const_table)
281 chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal);
283 lookup = (char*) g_hash_table_lookup (chunk->const_table, (gchar *)string);
287 lookup = g_string_chunk_insert (chunk, string);
288 g_hash_table_insert (chunk->const_table, lookup, lookup);
295 * g_string_chunk_insert_len:
296 * @chunk: a #GStringChunk
297 * @string: bytes to insert
298 * @len: number of bytes of @string to insert, or -1 to insert a
299 * nul-terminated string
301 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
302 * The copy is nul-terminated.
304 * Since this function does not stop at nul bytes, it is the caller's
305 * responsibility to ensure that @string has at least @len addressable
308 * The characters in the returned string can be changed, if necessary,
309 * though you should not change anything after the end of the string.
311 * Return value: a pointer to the copy of @string within the #GStringChunk
316 g_string_chunk_insert_len (GStringChunk *chunk,
323 g_return_val_if_fail (chunk != NULL, NULL);
326 size = strlen (string);
330 if ((chunk->storage_next + size + 1) > chunk->this_size)
332 gsize new_size = nearest_power (chunk->default_size, size + 1);
334 chunk->storage_list = g_slist_prepend (chunk->storage_list,
335 g_new (gchar, new_size));
337 chunk->this_size = new_size;
338 chunk->storage_next = 0;
341 pos = ((gchar *) chunk->storage_list->data) + chunk->storage_next;
343 *(pos + size) = '\0';
345 memcpy (pos, string, size);
347 chunk->storage_next += size + 1;
355 g_string_maybe_expand (GString* string,
358 if (string->len + len >= string->allocated_len)
360 string->allocated_len = nearest_power (1, string->len + len + 1);
361 string->str = g_realloc (string->str, string->allocated_len);
366 * g_string_sized_new:
367 * @dfl_size: the default size of the space allocated to
370 * Creates a new #GString, with enough space for @dfl_size
371 * bytes. This is useful if you are going to add a lot of
372 * text to the string and don't want it to be reallocated
375 * Returns: the new #GString
378 g_string_sized_new (gsize dfl_size)
380 GString *string = g_slice_new (GString);
382 string->allocated_len = 0;
386 g_string_maybe_expand (string, MAX (dfl_size, 2));
394 * @init: the initial text to copy into the string
396 * Creates a new #GString, initialized with the given string.
398 * Returns: the new #GString
401 g_string_new (const gchar *init)
405 if (init == NULL || *init == '\0')
406 string = g_string_sized_new (2);
412 string = g_string_sized_new (len + 2);
414 g_string_append_len (string, init, len);
422 * @init: initial contents of the string
423 * @len: length of @init to use
425 * Creates a new #GString with @len bytes of the @init buffer.
426 * Because a length is provided, @init need not be nul-terminated,
427 * and can contain embedded nul bytes.
429 * Since this function does not stop at nul bytes, it is the caller's
430 * responsibility to ensure that @init has at least @len addressable
433 * Returns: a new #GString
436 g_string_new_len (const gchar *init,
442 return g_string_new (init);
445 string = g_string_sized_new (len);
448 g_string_append_len (string, init, len);
456 * @string: a #GString
457 * @free_segment: if %TRUE the actual character data is freed as well
459 * Frees the memory allocated for the #GString.
460 * If @free_segment is %TRUE it also frees the character data.
462 * Returns: the character data of @string
463 * (i.e. %NULL if @free_segment is %TRUE)
466 g_string_free (GString *string,
467 gboolean free_segment)
471 g_return_val_if_fail (string != NULL, NULL);
475 g_free (string->str);
479 segment = string->str;
481 g_slice_free (GString, string);
489 * @v2: another #GString
491 * Compares two strings for equality, returning %TRUE if they are equal.
492 * For use with #GHashTable.
494 * Returns: %TRUE if they strings are the same length and contain the
498 g_string_equal (const GString *v,
502 GString *string1 = (GString *) v;
503 GString *string2 = (GString *) v2;
504 gsize i = string1->len;
506 if (i != string2->len)
524 * @str: a string to hash
526 * Creates a hash code for @str; for use with #GHashTable.
528 * Returns: hash code for @str
530 /* 31 bit hash function */
532 g_string_hash (const GString *str)
534 const gchar *p = str->str;
540 h = (h << 5) - h + *p;
549 * @string: the destination #GString. Its current contents
551 * @rval: the string to copy into @string
553 * Copies the bytes from a string into a #GString,
554 * destroying any previous contents. It is rather like
555 * the standard strcpy() function, except that you do not
556 * have to worry about having enough space to copy the string.
561 g_string_assign (GString *string,
564 g_return_val_if_fail (string != NULL, NULL);
565 g_return_val_if_fail (rval != NULL, string);
567 /* Make sure assigning to itself doesn't corrupt the string. */
568 if (string->str != rval)
570 /* Assigning from substring should be ok since g_string_truncate
572 g_string_truncate (string, 0);
573 g_string_append (string, rval);
581 * @string: a #GString
582 * @len: the new size of @string
584 * Cuts off the end of the GString, leaving the first @len bytes.
589 g_string_truncate (GString *string,
592 g_return_val_if_fail (string != NULL, NULL);
594 string->len = MIN (len, string->len);
595 string->str[string->len] = 0;
602 * @string: a #GString
603 * @len: the new length
605 * Sets the length of a #GString. If the length is less than
606 * the current length, the string will be truncated. If the
607 * length is greater than the current length, the contents
608 * of the newly added area are undefined. (However, as
609 * always, string->str[string->len] will be a nul byte.)
611 * Return value: @string
614 g_string_set_size (GString *string,
617 g_return_val_if_fail (string != NULL, NULL);
619 if (len >= string->allocated_len)
620 g_string_maybe_expand (string, len - string->len);
623 string->str[len] = 0;
629 * g_string_insert_len:
630 * @string: a #GString
631 * @pos: position in @string where insertion should
632 * happen, or -1 for at the end
633 * @val: bytes to insert
634 * @len: number of bytes of @val to insert
636 * Inserts @len bytes of @val into @string at @pos.
637 * Because @len is provided, @val may contain embedded
638 * nuls and need not be nul-terminated. If @pos is -1,
639 * bytes are inserted at the end of the string.
641 * Since this function does not stop at nul bytes, it is
642 * the caller's responsibility to ensure that @val has at
643 * least @len addressable bytes.
648 g_string_insert_len (GString *string,
653 g_return_val_if_fail (string != NULL, NULL);
654 g_return_val_if_fail (val != NULL, string);
662 g_return_val_if_fail (pos <= string->len, string);
664 /* Check whether val represents a substring of string. This test
665 probably violates chapter and verse of the C standards, since
666 ">=" and "<=" are only valid when val really is a substring.
667 In practice, it will work on modern archs. */
668 if (val >= string->str && val <= string->str + string->len)
670 gsize offset = val - string->str;
673 g_string_maybe_expand (string, len);
674 val = string->str + offset;
675 /* At this point, val is valid again. */
677 /* Open up space where we are going to insert. */
678 if (pos < string->len)
679 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
681 /* Move the source part before the gap, if any. */
684 precount = MIN (len, pos - offset);
685 memcpy (string->str + pos, val, precount);
688 /* Move the source part after the gap, if any. */
690 memcpy (string->str + pos + precount,
691 val + /* Already moved: */ precount + /* Space opened up: */ len,
696 g_string_maybe_expand (string, len);
698 /* If we aren't appending at the end, move a hunk
699 * of the old string to the end, opening up space
701 if (pos < string->len)
702 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
704 /* insert the new string */
706 string->str[pos] = *val;
708 memcpy (string->str + pos, val, len);
713 string->str[string->len] = 0;
718 #define SUB_DELIM_CHARS "!$&'()*+,;="
721 is_valid (char c, const char *reserved_chars_allowed)
723 if (g_ascii_isalnum (c) ||
730 if (reserved_chars_allowed &&
731 strchr (reserved_chars_allowed, c) != NULL)
738 gunichar_ok (gunichar c)
741 (c != (gunichar) -2) &&
742 (c != (gunichar) -1);
746 * g_string_append_uri_escaped:
747 * @string: a #GString
748 * @unescaped: a string
749 * @reserved_chars_allowed: a string of reserved characters allowed to be used
750 * @allow_utf8: set %TRUE if the escaped string may include UTF8 characters
752 * Appends @unescaped to @string, escaped any characters that
753 * are reserved in URIs using URI-style escape sequences.
760 g_string_append_uri_escaped (GString *string,
761 const char *unescaped,
762 const char *reserved_chars_allowed,
767 static const gchar hex[16] = "0123456789ABCDEF";
769 g_return_val_if_fail (string != NULL, NULL);
770 g_return_val_if_fail (unescaped != NULL, NULL);
772 end = unescaped + strlen (unescaped);
774 while ((c = *unescaped) != 0)
776 if (c >= 0x80 && allow_utf8 &&
777 gunichar_ok (g_utf8_get_char_validated (unescaped, end - unescaped)))
779 int len = g_utf8_skip [c];
780 g_string_append_len (string, unescaped, len);
783 else if (is_valid (c, reserved_chars_allowed))
785 g_string_append_c (string, c);
790 g_string_append_c (string, '%');
791 g_string_append_c (string, hex[((guchar)c) >> 4]);
792 g_string_append_c (string, hex[((guchar)c) & 0xf]);
802 * @string: a #GString
803 * @val: the string to append onto the end of @string
805 * Adds a string onto the end of a #GString, expanding
811 g_string_append (GString *string,
814 g_return_val_if_fail (string != NULL, NULL);
815 g_return_val_if_fail (val != NULL, string);
817 return g_string_insert_len (string, -1, val, -1);
821 * g_string_append_len:
822 * @string: a #GString
823 * @val: bytes to append
824 * @len: number of bytes of @val to use
826 * Appends @len bytes of @val to @string. Because @len is
827 * provided, @val may contain embedded nuls and need not
830 * Since this function does not stop at nul bytes, it is
831 * the caller's responsibility to ensure that @val has at
832 * least @len addressable bytes.
837 g_string_append_len (GString *string,
841 g_return_val_if_fail (string != NULL, NULL);
842 g_return_val_if_fail (val != NULL, string);
844 return g_string_insert_len (string, -1, val, len);
849 * @string: a #GString
850 * @c: the byte to append onto the end of @string
852 * Adds a byte onto the end of a #GString, expanding
857 #undef g_string_append_c
859 g_string_append_c (GString *string,
862 g_return_val_if_fail (string != NULL, NULL);
864 return g_string_insert_c (string, -1, c);
868 * g_string_append_unichar:
869 * @string: a #GString
870 * @wc: a Unicode character
872 * Converts a Unicode character into UTF-8, and appends it
875 * Return value: @string
878 g_string_append_unichar (GString *string,
881 g_return_val_if_fail (string != NULL, NULL);
883 return g_string_insert_unichar (string, -1, wc);
888 * @string: a #GString
889 * @val: the string to prepend on the start of @string
891 * Adds a string on to the start of a #GString,
892 * expanding it if necessary.
897 g_string_prepend (GString *string,
900 g_return_val_if_fail (string != NULL, NULL);
901 g_return_val_if_fail (val != NULL, string);
903 return g_string_insert_len (string, 0, val, -1);
907 * g_string_prepend_len:
908 * @string: a #GString
909 * @val: bytes to prepend
910 * @len: number of bytes in @val to prepend
912 * Prepends @len bytes of @val to @string.
913 * Because @len is provided, @val may contain
914 * embedded nuls and need not be nul-terminated.
916 * Since this function does not stop at nul bytes,
917 * it is the caller's responsibility to ensure that
918 * @val has at least @len addressable bytes.
923 g_string_prepend_len (GString *string,
927 g_return_val_if_fail (string != NULL, NULL);
928 g_return_val_if_fail (val != NULL, string);
930 return g_string_insert_len (string, 0, val, len);
934 * g_string_prepend_c:
935 * @string: a #GString
936 * @c: the byte to prepend on the start of the #GString
938 * Adds a byte onto the start of a #GString,
939 * expanding it if necessary.
944 g_string_prepend_c (GString *string,
947 g_return_val_if_fail (string != NULL, NULL);
949 return g_string_insert_c (string, 0, c);
953 * g_string_prepend_unichar:
954 * @string: a #GString
955 * @wc: a Unicode character
957 * Converts a Unicode character into UTF-8, and prepends it
960 * Return value: @string
963 g_string_prepend_unichar (GString *string,
966 g_return_val_if_fail (string != NULL, NULL);
968 return g_string_insert_unichar (string, 0, wc);
973 * @string: a #GString
974 * @pos: the position to insert the copy of the string
975 * @val: the string to insert
977 * Inserts a copy of a string into a #GString,
978 * expanding it if necessary.
983 g_string_insert (GString *string,
987 g_return_val_if_fail (string != NULL, NULL);
988 g_return_val_if_fail (val != NULL, string);
990 g_return_val_if_fail (pos <= string->len, string);
992 return g_string_insert_len (string, pos, val, -1);
997 * @string: a #GString
998 * @pos: the position to insert the byte
999 * @c: the byte to insert
1001 * Inserts a byte into a #GString, expanding it if necessary.
1006 g_string_insert_c (GString *string,
1010 g_return_val_if_fail (string != NULL, NULL);
1012 g_string_maybe_expand (string, 1);
1017 g_return_val_if_fail (pos <= string->len, string);
1019 /* If not just an append, move the old stuff */
1020 if (pos < string->len)
1021 g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
1023 string->str[pos] = c;
1027 string->str[string->len] = 0;
1033 * g_string_insert_unichar:
1034 * @string: a #GString
1035 * @pos: the position at which to insert character, or -1 to
1036 * append at the end of the string
1037 * @wc: a Unicode character
1039 * Converts a Unicode character into UTF-8, and insert it
1040 * into the string at the given position.
1042 * Return value: @string
1045 g_string_insert_unichar (GString *string,
1049 gint charlen, first, i;
1052 g_return_val_if_fail (string != NULL, NULL);
1054 /* Code copied from g_unichar_to_utf() */
1060 else if (wc < 0x800)
1065 else if (wc < 0x10000)
1070 else if (wc < 0x200000)
1075 else if (wc < 0x4000000)
1085 /* End of copied code */
1087 g_string_maybe_expand (string, charlen);
1092 g_return_val_if_fail (pos <= string->len, string);
1094 /* If not just an append, move the old stuff */
1095 if (pos < string->len)
1096 g_memmove (string->str + pos + charlen, string->str + pos, string->len - pos);
1098 dest = string->str + pos;
1099 /* Code copied from g_unichar_to_utf() */
1100 for (i = charlen - 1; i > 0; --i)
1102 dest[i] = (wc & 0x3f) | 0x80;
1105 dest[0] = wc | first;
1106 /* End of copied code */
1108 string->len += charlen;
1110 string->str[string->len] = 0;
1116 * g_string_overwrite:
1117 * @string: a #GString
1118 * @pos: the position at which to start overwriting
1119 * @val: the string that will overwrite the @string starting at @pos
1121 * Overwrites part of a string, lengthening it if necessary.
1123 * Return value: @string
1128 g_string_overwrite (GString *string,
1132 g_return_val_if_fail (val != NULL, string);
1133 return g_string_overwrite_len (string, pos, val, strlen (val));
1137 * g_string_overwrite_len:
1138 * @string: a #GString
1139 * @pos: the position at which to start overwriting
1140 * @val: the string that will overwrite the @string starting at @pos
1141 * @len: the number of bytes to write from @val
1143 * Overwrites part of a string, lengthening it if necessary.
1144 * This function will work with embedded nuls.
1146 * Return value: @string
1151 g_string_overwrite_len (GString *string,
1158 g_return_val_if_fail (string != NULL, NULL);
1163 g_return_val_if_fail (val != NULL, string);
1164 g_return_val_if_fail (pos <= string->len, string);
1171 if (end > string->len)
1172 g_string_maybe_expand (string, end - string->len);
1174 memcpy (string->str + pos, val, len);
1176 if (end > string->len)
1178 string->str[end] = '\0';
1187 * @string: a #GString
1188 * @pos: the position of the content to remove
1189 * @len: the number of bytes to remove, or -1 to remove all
1192 * Removes @len bytes from a #GString, starting at position @pos.
1193 * The rest of the #GString is shifted down to fill the gap.
1198 g_string_erase (GString *string,
1202 g_return_val_if_fail (string != NULL, NULL);
1203 g_return_val_if_fail (pos >= 0, string);
1204 g_return_val_if_fail (pos <= string->len, string);
1207 len = string->len - pos;
1210 g_return_val_if_fail (pos + len <= string->len, string);
1212 if (pos + len < string->len)
1213 g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
1218 string->str[string->len] = 0;
1224 * g_string_ascii_down:
1225 * @string: a GString
1227 * Converts all upper case ASCII letters to lower case ASCII letters.
1229 * Return value: passed-in @string pointer, with all the upper case
1230 * characters converted to lower case in place, with
1231 * semantics that exactly match g_ascii_tolower().
1234 g_string_ascii_down (GString *string)
1239 g_return_val_if_fail (string != NULL, NULL);
1246 *s = g_ascii_tolower (*s);
1255 * g_string_ascii_up:
1256 * @string: a GString
1258 * Converts all lower case ASCII letters to upper case ASCII letters.
1260 * Return value: passed-in @string pointer, with all the lower case
1261 * characters converted to upper case in place, with
1262 * semantics that exactly match g_ascii_toupper().
1265 g_string_ascii_up (GString *string)
1270 g_return_val_if_fail (string != NULL, NULL);
1277 *s = g_ascii_toupper (*s);
1287 * @string: a #GString
1289 * Converts a #GString to lowercase.
1291 * Returns: the #GString.
1293 * Deprecated:2.2: This function uses the locale-specific
1294 * tolower() function, which is almost never the right thing.
1295 * Use g_string_ascii_down() or g_utf8_strdown() instead.
1298 g_string_down (GString *string)
1303 g_return_val_if_fail (string != NULL, NULL);
1306 s = (guchar *) string->str;
1321 * @string: a #GString
1323 * Converts a #GString to uppercase.
1325 * Return value: @string
1327 * Deprecated:2.2: This function uses the locale-specific
1328 * toupper() function, which is almost never the right thing.
1329 * Use g_string_ascii_up() or g_utf8_strup() instead.
1332 g_string_up (GString *string)
1337 g_return_val_if_fail (string != NULL, NULL);
1340 s = (guchar *) string->str;
1354 * g_string_append_vprintf:
1355 * @string: a #GString
1356 * @format: the string format. See the printf() documentation
1357 * @args: the list of arguments to insert in the output
1359 * Appends a formatted string onto the end of a #GString.
1360 * This function is similar to g_string_append_printf()
1361 * except that the arguments to the format string are passed
1367 g_string_append_vprintf (GString *string,
1368 const gchar *format,
1374 g_return_if_fail (string != NULL);
1375 g_return_if_fail (format != NULL);
1377 len = g_vasprintf (&buf, format, args);
1381 g_string_maybe_expand (string, len);
1382 memcpy (string->str + string->len, buf, len + 1);
1390 * @string: a #GString
1391 * @format: the string format. See the printf() documentation
1392 * @args: the parameters to insert into the format string
1394 * Writes a formatted string into a #GString.
1395 * This function is similar to g_string_printf() except that
1396 * the arguments to the format string are passed as a va_list.
1401 g_string_vprintf (GString *string,
1402 const gchar *format,
1405 g_string_truncate (string, 0);
1406 g_string_append_vprintf (string, format, args);
1411 * @string: a #GString
1412 * @format: the string format. See the sprintf() documentation
1413 * @Varargs: the parameters to insert into the format string
1415 * Writes a formatted string into a #GString.
1416 * This is similar to the standard sprintf() function,
1417 * except that the #GString buffer automatically expands
1418 * to contain the results. The previous contents of the
1419 * #GString are destroyed.
1421 * Deprecated: This function has been renamed to g_string_printf().
1426 * @string: a #GString
1427 * @format: the string format. See the printf() documentation
1428 * @Varargs: the parameters to insert into the format string
1430 * Writes a formatted string into a #GString.
1431 * This is similar to the standard sprintf() function,
1432 * except that the #GString buffer automatically expands
1433 * to contain the results. The previous contents of the
1434 * #GString are destroyed.
1437 g_string_printf (GString *string,
1438 const gchar *format,
1443 g_string_truncate (string, 0);
1445 va_start (args, format);
1446 g_string_append_vprintf (string, format, args);
1451 * g_string_sprintfa:
1452 * @string: a #GString
1453 * @format: the string format. See the sprintf() documentation
1454 * @Varargs: the parameters to insert into the format string
1456 * Appends a formatted string onto the end of a #GString.
1457 * This function is similar to g_string_sprintf() except that
1458 * the text is appended to the #GString.
1460 * Deprecated: This function has been renamed to g_string_append_printf()
1464 * g_string_append_printf:
1465 * @string: a #GString
1466 * @format: the string format. See the printf() documentation
1467 * @Varargs: the parameters to insert into the format string
1469 * Appends a formatted string onto the end of a #GString.
1470 * This function is similar to g_string_printf() except
1471 * that the text is appended to the #GString.
1474 g_string_append_printf (GString *string,
1475 const gchar *format,
1480 va_start (args, format);
1481 g_string_append_vprintf (string, format, args);
1485 #define __G_STRING_C__
1486 #include "galiasdef.c"