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/.
48 * SECTION: string_chunks
49 * @title: String Chunks
50 * @short_description: efficient storage of groups of strings
52 * String chunks are used to store groups of strings. Memory is
53 * allocated in blocks, and as strings are added to the #GStringChunk
54 * they are copied into the next free position in a block. When a block
55 * is full a new block is allocated.
57 * When storing a large number of strings, string chunks are more
58 * efficient than using g_strdup() since fewer calls to malloc() are
59 * needed, and less memory is wasted in memory allocation overheads.
61 * By adding strings with g_string_chunk_insert_const() it is also
62 * possible to remove duplicates.
64 * To create a new #GStringChunk use g_string_chunk_new().
66 * To add strings to a #GStringChunk use g_string_chunk_insert().
68 * To add strings to a #GStringChunk, but without duplicating strings
69 * which are already in the #GStringChunk, use
70 * g_string_chunk_insert_const().
72 * To free the entire #GStringChunk use g_string_chunk_free(). It is
73 * not possible to free individual strings.
79 * An opaque data structure representing String Chunks. It should only
80 * be accessed by using the following functions.
84 GHashTable *const_table;
97 * @v2: a key to compare with @v1
99 * Compares two strings for byte-by-byte equality and returns %TRUE
100 * if they are equal. It can be passed to g_hash_table_new() as the
101 * @key_equal_func parameter, when using strings as keys in a #GHashTable.
103 * Note that this function is primarily meant as a hash table comparison
104 * function. For a general-purpose, %NULL-safe string comparison function,
107 * Returns: %TRUE if the two keys match
110 g_str_equal (gconstpointer v1,
113 const gchar *string1 = v1;
114 const gchar *string2 = v2;
116 return strcmp (string1, string2) == 0;
123 * Converts a string to a hash value.
124 * It can be passed to g_hash_table_new() as the @hash_func
125 * parameter, when using strings as keys in a #GHashTable.
127 * Returns: a hash value corresponding to the key
130 g_str_hash (gconstpointer v)
132 /* 31 bit hash function */
133 const signed char *p = v;
137 for (p += 1; *p != '\0'; p++)
138 h = (h << 5) - h + *p;
143 #define MY_MAXSIZE ((gsize)-1)
146 nearest_power (gsize base, gsize num)
148 if (num > MY_MAXSIZE / 2)
167 * g_string_chunk_new:
168 * @size: the default size of the blocks of memory which are
169 * allocated to store the strings. If a particular string
170 * is larger than this default size, a larger block of
171 * memory will be allocated for it.
173 * Creates a new #GStringChunk.
175 * Returns: a new #GStringChunk
178 g_string_chunk_new (gsize size)
180 GStringChunk *new_chunk = g_new (GStringChunk, 1);
181 gsize actual_size = 1;
183 actual_size = nearest_power (1, size);
185 new_chunk->const_table = NULL;
186 new_chunk->storage_list = NULL;
187 new_chunk->storage_next = actual_size;
188 new_chunk->default_size = actual_size;
189 new_chunk->this_size = actual_size;
195 * g_string_chunk_free:
196 * @chunk: a #GStringChunk
198 * Frees all memory allocated by the #GStringChunk.
199 * After calling g_string_chunk_free() it is not safe to
200 * access any of the strings which were contained within it.
203 g_string_chunk_free (GStringChunk *chunk)
207 g_return_if_fail (chunk != NULL);
209 if (chunk->storage_list)
211 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
212 g_free (tmp_list->data);
214 g_slist_free (chunk->storage_list);
217 if (chunk->const_table)
218 g_hash_table_destroy (chunk->const_table);
224 * g_string_chunk_clear:
225 * @chunk: a #GStringChunk
227 * Frees all strings contained within the #GStringChunk.
228 * After calling g_string_chunk_clear() it is not safe to
229 * access any of the strings which were contained within it.
234 g_string_chunk_clear (GStringChunk *chunk)
238 g_return_if_fail (chunk != NULL);
240 if (chunk->storage_list)
242 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
243 g_free (tmp_list->data);
245 g_slist_free (chunk->storage_list);
247 chunk->storage_list = NULL;
248 chunk->storage_next = chunk->default_size;
249 chunk->this_size = chunk->default_size;
252 if (chunk->const_table)
253 g_hash_table_remove_all (chunk->const_table);
257 * g_string_chunk_insert:
258 * @chunk: a #GStringChunk
259 * @string: the string to add
261 * Adds a copy of @string to the #GStringChunk.
262 * It returns a pointer to the new copy of the string
263 * in the #GStringChunk. The characters in the string
264 * can be changed, if necessary, though you should not
265 * change anything after the end of the string.
267 * Unlike g_string_chunk_insert_const(), this function
268 * does not check for duplicates. Also strings added
269 * with g_string_chunk_insert() will not be searched
270 * by g_string_chunk_insert_const() when looking for
273 * Returns: a pointer to the copy of @string within
277 g_string_chunk_insert (GStringChunk *chunk,
280 g_return_val_if_fail (chunk != NULL, NULL);
282 return g_string_chunk_insert_len (chunk, string, -1);
286 * g_string_chunk_insert_const:
287 * @chunk: a #GStringChunk
288 * @string: the string to add
290 * Adds a copy of @string to the #GStringChunk, unless the same
291 * string has already been added to the #GStringChunk with
292 * g_string_chunk_insert_const().
294 * This function is useful if you need to copy a large number
295 * of strings but do not want to waste space storing duplicates.
296 * But you must remember that there may be several pointers to
297 * the same string, and so any changes made to the strings
298 * should be done very carefully.
300 * Note that g_string_chunk_insert_const() will not return a
301 * pointer to a string added with g_string_chunk_insert(), even
304 * Returns: a pointer to the new or existing copy of @string
305 * within the #GStringChunk
308 g_string_chunk_insert_const (GStringChunk *chunk,
313 g_return_val_if_fail (chunk != NULL, NULL);
315 if (!chunk->const_table)
316 chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal);
318 lookup = (char*) g_hash_table_lookup (chunk->const_table, (gchar *)string);
322 lookup = g_string_chunk_insert (chunk, string);
323 g_hash_table_insert (chunk->const_table, lookup, lookup);
330 * g_string_chunk_insert_len:
331 * @chunk: a #GStringChunk
332 * @string: bytes to insert
333 * @len: number of bytes of @string to insert, or -1 to insert a
334 * nul-terminated string
336 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
337 * The copy is nul-terminated.
339 * Since this function does not stop at nul bytes, it is the caller's
340 * responsibility to ensure that @string has at least @len addressable
343 * The characters in the returned string can be changed, if necessary,
344 * though you should not change anything after the end of the string.
346 * Return value: a pointer to the copy of @string within the #GStringChunk
351 g_string_chunk_insert_len (GStringChunk *chunk,
358 g_return_val_if_fail (chunk != NULL, NULL);
361 size = strlen (string);
365 if ((chunk->storage_next + size + 1) > chunk->this_size)
367 gsize new_size = nearest_power (chunk->default_size, size + 1);
369 chunk->storage_list = g_slist_prepend (chunk->storage_list,
370 g_new (gchar, new_size));
372 chunk->this_size = new_size;
373 chunk->storage_next = 0;
376 pos = ((gchar *) chunk->storage_list->data) + chunk->storage_next;
378 *(pos + size) = '\0';
380 memcpy (pos, string, size);
382 chunk->storage_next += size + 1;
390 g_string_maybe_expand (GString* string,
393 if (string->len + len >= string->allocated_len)
395 string->allocated_len = nearest_power (1, string->len + len + 1);
396 string->str = g_realloc (string->str, string->allocated_len);
401 * g_string_sized_new:
402 * @dfl_size: the default size of the space allocated to
405 * Creates a new #GString, with enough space for @dfl_size
406 * bytes. This is useful if you are going to add a lot of
407 * text to the string and don't want it to be reallocated
410 * Returns: the new #GString
413 g_string_sized_new (gsize dfl_size)
415 GString *string = g_slice_new (GString);
417 string->allocated_len = 0;
421 g_string_maybe_expand (string, MAX (dfl_size, 2));
429 * @init: the initial text to copy into the string
431 * Creates a new #GString, initialized with the given string.
433 * Returns: the new #GString
436 g_string_new (const gchar *init)
440 if (init == NULL || *init == '\0')
441 string = g_string_sized_new (2);
447 string = g_string_sized_new (len + 2);
449 g_string_append_len (string, init, len);
457 * @init: initial contents of the string
458 * @len: length of @init to use
460 * Creates a new #GString with @len bytes of the @init buffer.
461 * Because a length is provided, @init need not be nul-terminated,
462 * and can contain embedded nul bytes.
464 * Since this function does not stop at nul bytes, it is the caller's
465 * responsibility to ensure that @init has at least @len addressable
468 * Returns: a new #GString
471 g_string_new_len (const gchar *init,
477 return g_string_new (init);
480 string = g_string_sized_new (len);
483 g_string_append_len (string, init, len);
491 * @string: a #GString
492 * @free_segment: if %TRUE the actual character data is freed as well
494 * Frees the memory allocated for the #GString.
495 * If @free_segment is %TRUE it also frees the character data.
497 * Returns: the character data of @string
498 * (i.e. %NULL if @free_segment is %TRUE)
501 g_string_free (GString *string,
502 gboolean free_segment)
506 g_return_val_if_fail (string != NULL, NULL);
510 g_free (string->str);
514 segment = string->str;
516 g_slice_free (GString, string);
524 * @v2: another #GString
526 * Compares two strings for equality, returning %TRUE if they are equal.
527 * For use with #GHashTable.
529 * Returns: %TRUE if they strings are the same length and contain the
533 g_string_equal (const GString *v,
537 GString *string1 = (GString *) v;
538 GString *string2 = (GString *) v2;
539 gsize i = string1->len;
541 if (i != string2->len)
559 * @str: a string to hash
561 * Creates a hash code for @str; for use with #GHashTable.
563 * Returns: hash code for @str
565 /* 31 bit hash function */
567 g_string_hash (const GString *str)
569 const gchar *p = str->str;
575 h = (h << 5) - h + *p;
584 * @string: the destination #GString. Its current contents
586 * @rval: the string to copy into @string
588 * Copies the bytes from a string into a #GString,
589 * destroying any previous contents. It is rather like
590 * the standard strcpy() function, except that you do not
591 * have to worry about having enough space to copy the string.
596 g_string_assign (GString *string,
599 g_return_val_if_fail (string != NULL, NULL);
600 g_return_val_if_fail (rval != NULL, string);
602 /* Make sure assigning to itself doesn't corrupt the string. */
603 if (string->str != rval)
605 /* Assigning from substring should be ok since g_string_truncate
607 g_string_truncate (string, 0);
608 g_string_append (string, rval);
616 * @string: a #GString
617 * @len: the new size of @string
619 * Cuts off the end of the GString, leaving the first @len bytes.
624 g_string_truncate (GString *string,
627 g_return_val_if_fail (string != NULL, NULL);
629 string->len = MIN (len, string->len);
630 string->str[string->len] = 0;
637 * @string: a #GString
638 * @len: the new length
640 * Sets the length of a #GString. If the length is less than
641 * the current length, the string will be truncated. If the
642 * length is greater than the current length, the contents
643 * of the newly added area are undefined. (However, as
644 * always, string->str[string->len] will be a nul byte.)
646 * Return value: @string
649 g_string_set_size (GString *string,
652 g_return_val_if_fail (string != NULL, NULL);
654 if (len >= string->allocated_len)
655 g_string_maybe_expand (string, len - string->len);
658 string->str[len] = 0;
664 * g_string_insert_len:
665 * @string: a #GString
666 * @pos: position in @string where insertion should
667 * happen, or -1 for at the end
668 * @val: bytes to insert
669 * @len: number of bytes of @val to insert
671 * Inserts @len bytes of @val into @string at @pos.
672 * Because @len is provided, @val may contain embedded
673 * nuls and need not be nul-terminated. If @pos is -1,
674 * bytes are inserted at the end of the string.
676 * Since this function does not stop at nul bytes, it is
677 * the caller's responsibility to ensure that @val has at
678 * least @len addressable bytes.
683 g_string_insert_len (GString *string,
688 g_return_val_if_fail (string != NULL, NULL);
689 g_return_val_if_fail (len == 0 || val != NULL, string);
700 g_return_val_if_fail (pos <= string->len, string);
702 /* Check whether val represents a substring of string. This test
703 probably violates chapter and verse of the C standards, since
704 ">=" and "<=" are only valid when val really is a substring.
705 In practice, it will work on modern archs. */
706 if (val >= string->str && val <= string->str + string->len)
708 gsize offset = val - string->str;
711 g_string_maybe_expand (string, len);
712 val = string->str + offset;
713 /* At this point, val is valid again. */
715 /* Open up space where we are going to insert. */
716 if (pos < string->len)
717 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
719 /* Move the source part before the gap, if any. */
722 precount = MIN (len, pos - offset);
723 memcpy (string->str + pos, val, precount);
726 /* Move the source part after the gap, if any. */
728 memcpy (string->str + pos + precount,
729 val + /* Already moved: */ precount + /* Space opened up: */ len,
734 g_string_maybe_expand (string, len);
736 /* If we aren't appending at the end, move a hunk
737 * of the old string to the end, opening up space
739 if (pos < string->len)
740 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
742 /* insert the new string */
744 string->str[pos] = *val;
746 memcpy (string->str + pos, val, len);
751 string->str[string->len] = 0;
756 #define SUB_DELIM_CHARS "!$&'()*+,;="
759 is_valid (char c, const char *reserved_chars_allowed)
761 if (g_ascii_isalnum (c) ||
768 if (reserved_chars_allowed &&
769 strchr (reserved_chars_allowed, c) != NULL)
776 gunichar_ok (gunichar c)
779 (c != (gunichar) -2) &&
780 (c != (gunichar) -1);
784 * g_string_append_uri_escaped:
785 * @string: a #GString
786 * @unescaped: a string
787 * @reserved_chars_allowed: a string of reserved characters allowed to be used, or %NULL
788 * @allow_utf8: set %TRUE if the escaped string may include UTF8 characters
790 * Appends @unescaped to @string, escaped any characters that
791 * are reserved in URIs using URI-style escape sequences.
798 g_string_append_uri_escaped (GString *string,
799 const char *unescaped,
800 const char *reserved_chars_allowed,
805 static const gchar hex[16] = "0123456789ABCDEF";
807 g_return_val_if_fail (string != NULL, NULL);
808 g_return_val_if_fail (unescaped != NULL, NULL);
810 end = unescaped + strlen (unescaped);
812 while ((c = *unescaped) != 0)
814 if (c >= 0x80 && allow_utf8 &&
815 gunichar_ok (g_utf8_get_char_validated (unescaped, end - unescaped)))
817 int len = g_utf8_skip [c];
818 g_string_append_len (string, unescaped, len);
821 else if (is_valid (c, reserved_chars_allowed))
823 g_string_append_c (string, c);
828 g_string_append_c (string, '%');
829 g_string_append_c (string, hex[((guchar)c) >> 4]);
830 g_string_append_c (string, hex[((guchar)c) & 0xf]);
840 * @string: a #GString
841 * @val: the string to append onto the end of @string
843 * Adds a string onto the end of a #GString, expanding
849 g_string_append (GString *string,
852 g_return_val_if_fail (string != NULL, NULL);
853 g_return_val_if_fail (val != NULL, string);
855 return g_string_insert_len (string, -1, val, -1);
859 * g_string_append_len:
860 * @string: a #GString
861 * @val: bytes to append
862 * @len: number of bytes of @val to use
864 * Appends @len bytes of @val to @string. Because @len is
865 * provided, @val may contain embedded nuls and need not
868 * Since this function does not stop at nul bytes, it is
869 * the caller's responsibility to ensure that @val has at
870 * least @len addressable bytes.
875 g_string_append_len (GString *string,
879 g_return_val_if_fail (string != NULL, NULL);
880 g_return_val_if_fail (len == 0 || val != NULL, string);
882 return g_string_insert_len (string, -1, val, len);
887 * @string: a #GString
888 * @c: the byte to append onto the end of @string
890 * Adds a byte onto the end of a #GString, expanding
895 #undef g_string_append_c
897 g_string_append_c (GString *string,
900 g_return_val_if_fail (string != NULL, NULL);
902 return g_string_insert_c (string, -1, c);
906 * g_string_append_unichar:
907 * @string: a #GString
908 * @wc: a Unicode character
910 * Converts a Unicode character into UTF-8, and appends it
913 * Return value: @string
916 g_string_append_unichar (GString *string,
919 g_return_val_if_fail (string != NULL, NULL);
921 return g_string_insert_unichar (string, -1, wc);
926 * @string: a #GString
927 * @val: the string to prepend on the start of @string
929 * Adds a string on to the start of a #GString,
930 * expanding it if necessary.
935 g_string_prepend (GString *string,
938 g_return_val_if_fail (string != NULL, NULL);
939 g_return_val_if_fail (val != NULL, string);
941 return g_string_insert_len (string, 0, val, -1);
945 * g_string_prepend_len:
946 * @string: a #GString
947 * @val: bytes to prepend
948 * @len: number of bytes in @val to prepend
950 * Prepends @len bytes of @val to @string.
951 * Because @len is provided, @val may contain
952 * embedded nuls and need not be nul-terminated.
954 * Since this function does not stop at nul bytes,
955 * it is the caller's responsibility to ensure that
956 * @val has at least @len addressable bytes.
961 g_string_prepend_len (GString *string,
965 g_return_val_if_fail (string != NULL, NULL);
966 g_return_val_if_fail (val != NULL, string);
968 return g_string_insert_len (string, 0, val, len);
972 * g_string_prepend_c:
973 * @string: a #GString
974 * @c: the byte to prepend on the start of the #GString
976 * Adds a byte onto the start of a #GString,
977 * expanding it if necessary.
982 g_string_prepend_c (GString *string,
985 g_return_val_if_fail (string != NULL, NULL);
987 return g_string_insert_c (string, 0, c);
991 * g_string_prepend_unichar:
992 * @string: a #GString
993 * @wc: a Unicode character
995 * Converts a Unicode character into UTF-8, and prepends it
998 * Return value: @string
1001 g_string_prepend_unichar (GString *string,
1004 g_return_val_if_fail (string != NULL, NULL);
1006 return g_string_insert_unichar (string, 0, wc);
1011 * @string: a #GString
1012 * @pos: the position to insert the copy of the string
1013 * @val: the string to insert
1015 * Inserts a copy of a string into a #GString,
1016 * expanding it if necessary.
1021 g_string_insert (GString *string,
1025 g_return_val_if_fail (string != NULL, NULL);
1026 g_return_val_if_fail (val != NULL, string);
1028 g_return_val_if_fail (pos <= string->len, string);
1030 return g_string_insert_len (string, pos, val, -1);
1034 * g_string_insert_c:
1035 * @string: a #GString
1036 * @pos: the position to insert the byte
1037 * @c: the byte to insert
1039 * Inserts a byte into a #GString, expanding it if necessary.
1044 g_string_insert_c (GString *string,
1048 g_return_val_if_fail (string != NULL, NULL);
1050 g_string_maybe_expand (string, 1);
1055 g_return_val_if_fail (pos <= string->len, string);
1057 /* If not just an append, move the old stuff */
1058 if (pos < string->len)
1059 g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
1061 string->str[pos] = c;
1065 string->str[string->len] = 0;
1071 * g_string_insert_unichar:
1072 * @string: a #GString
1073 * @pos: the position at which to insert character, or -1 to
1074 * append at the end of the string
1075 * @wc: a Unicode character
1077 * Converts a Unicode character into UTF-8, and insert it
1078 * into the string at the given position.
1080 * Return value: @string
1083 g_string_insert_unichar (GString *string,
1087 gint charlen, first, i;
1090 g_return_val_if_fail (string != NULL, NULL);
1092 /* Code copied from g_unichar_to_utf() */
1098 else if (wc < 0x800)
1103 else if (wc < 0x10000)
1108 else if (wc < 0x200000)
1113 else if (wc < 0x4000000)
1123 /* End of copied code */
1125 g_string_maybe_expand (string, charlen);
1130 g_return_val_if_fail (pos <= string->len, string);
1132 /* If not just an append, move the old stuff */
1133 if (pos < string->len)
1134 g_memmove (string->str + pos + charlen, string->str + pos, string->len - pos);
1136 dest = string->str + pos;
1137 /* Code copied from g_unichar_to_utf() */
1138 for (i = charlen - 1; i > 0; --i)
1140 dest[i] = (wc & 0x3f) | 0x80;
1143 dest[0] = wc | first;
1144 /* End of copied code */
1146 string->len += charlen;
1148 string->str[string->len] = 0;
1154 * g_string_overwrite:
1155 * @string: a #GString
1156 * @pos: the position at which to start overwriting
1157 * @val: the string that will overwrite the @string starting at @pos
1159 * Overwrites part of a string, lengthening it if necessary.
1161 * Return value: @string
1166 g_string_overwrite (GString *string,
1170 g_return_val_if_fail (val != NULL, string);
1171 return g_string_overwrite_len (string, pos, val, strlen (val));
1175 * g_string_overwrite_len:
1176 * @string: a #GString
1177 * @pos: the position at which to start overwriting
1178 * @val: the string that will overwrite the @string starting at @pos
1179 * @len: the number of bytes to write from @val
1181 * Overwrites part of a string, lengthening it if necessary.
1182 * This function will work with embedded nuls.
1184 * Return value: @string
1189 g_string_overwrite_len (GString *string,
1196 g_return_val_if_fail (string != NULL, NULL);
1201 g_return_val_if_fail (val != NULL, string);
1202 g_return_val_if_fail (pos <= string->len, string);
1209 if (end > string->len)
1210 g_string_maybe_expand (string, end - string->len);
1212 memcpy (string->str + pos, val, len);
1214 if (end > string->len)
1216 string->str[end] = '\0';
1225 * @string: a #GString
1226 * @pos: the position of the content to remove
1227 * @len: the number of bytes to remove, or -1 to remove all
1230 * Removes @len bytes from a #GString, starting at position @pos.
1231 * The rest of the #GString is shifted down to fill the gap.
1236 g_string_erase (GString *string,
1240 g_return_val_if_fail (string != NULL, NULL);
1241 g_return_val_if_fail (pos >= 0, string);
1242 g_return_val_if_fail (pos <= string->len, string);
1245 len = string->len - pos;
1248 g_return_val_if_fail (pos + len <= string->len, string);
1250 if (pos + len < string->len)
1251 g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
1256 string->str[string->len] = 0;
1262 * g_string_ascii_down:
1263 * @string: a GString
1265 * Converts all upper case ASCII letters to lower case ASCII letters.
1267 * Return value: passed-in @string pointer, with all the upper case
1268 * characters converted to lower case in place, with
1269 * semantics that exactly match g_ascii_tolower().
1272 g_string_ascii_down (GString *string)
1277 g_return_val_if_fail (string != NULL, NULL);
1284 *s = g_ascii_tolower (*s);
1293 * g_string_ascii_up:
1294 * @string: a GString
1296 * Converts all lower case ASCII letters to upper case ASCII letters.
1298 * Return value: passed-in @string pointer, with all the lower case
1299 * characters converted to upper case in place, with
1300 * semantics that exactly match g_ascii_toupper().
1303 g_string_ascii_up (GString *string)
1308 g_return_val_if_fail (string != NULL, NULL);
1315 *s = g_ascii_toupper (*s);
1325 * @string: a #GString
1327 * Converts a #GString to lowercase.
1329 * Returns: the #GString.
1331 * Deprecated:2.2: This function uses the locale-specific
1332 * tolower() function, which is almost never the right thing.
1333 * Use g_string_ascii_down() or g_utf8_strdown() instead.
1336 g_string_down (GString *string)
1341 g_return_val_if_fail (string != NULL, NULL);
1344 s = (guchar *) string->str;
1359 * @string: a #GString
1361 * Converts a #GString to uppercase.
1363 * Return value: @string
1365 * Deprecated:2.2: This function uses the locale-specific
1366 * toupper() function, which is almost never the right thing.
1367 * Use g_string_ascii_up() or g_utf8_strup() instead.
1370 g_string_up (GString *string)
1375 g_return_val_if_fail (string != NULL, NULL);
1378 s = (guchar *) string->str;
1392 * g_string_append_vprintf:
1393 * @string: a #GString
1394 * @format: the string format. See the printf() documentation
1395 * @args: the list of arguments to insert in the output
1397 * Appends a formatted string onto the end of a #GString.
1398 * This function is similar to g_string_append_printf()
1399 * except that the arguments to the format string are passed
1405 g_string_append_vprintf (GString *string,
1406 const gchar *format,
1412 g_return_if_fail (string != NULL);
1413 g_return_if_fail (format != NULL);
1415 len = g_vasprintf (&buf, format, args);
1419 g_string_maybe_expand (string, len);
1420 memcpy (string->str + string->len, buf, len + 1);
1428 * @string: a #GString
1429 * @format: the string format. See the printf() documentation
1430 * @args: the parameters to insert into the format string
1432 * Writes a formatted string into a #GString.
1433 * This function is similar to g_string_printf() except that
1434 * the arguments to the format string are passed as a va_list.
1439 g_string_vprintf (GString *string,
1440 const gchar *format,
1443 g_string_truncate (string, 0);
1444 g_string_append_vprintf (string, format, args);
1449 * @string: a #GString
1450 * @format: the string format. See the sprintf() documentation
1451 * @Varargs: the parameters to insert into the format string
1453 * Writes a formatted string into a #GString.
1454 * This is similar to the standard sprintf() function,
1455 * except that the #GString buffer automatically expands
1456 * to contain the results. The previous contents of the
1457 * #GString are destroyed.
1459 * Deprecated: This function has been renamed to g_string_printf().
1464 * @string: a #GString
1465 * @format: the string format. See the printf() documentation
1466 * @Varargs: the parameters to insert into the format string
1468 * Writes a formatted string into a #GString.
1469 * This is similar to the standard sprintf() function,
1470 * except that the #GString buffer automatically expands
1471 * to contain the results. The previous contents of the
1472 * #GString are destroyed.
1475 g_string_printf (GString *string,
1476 const gchar *format,
1481 g_string_truncate (string, 0);
1483 va_start (args, format);
1484 g_string_append_vprintf (string, format, args);
1489 * g_string_sprintfa:
1490 * @string: a #GString
1491 * @format: the string format. See the sprintf() documentation
1492 * @Varargs: the parameters to insert into the format string
1494 * Appends a formatted string onto the end of a #GString.
1495 * This function is similar to g_string_sprintf() except that
1496 * the text is appended to the #GString.
1498 * Deprecated: This function has been renamed to g_string_append_printf()
1502 * g_string_append_printf:
1503 * @string: a #GString
1504 * @format: the string format. See the printf() documentation
1505 * @Varargs: the parameters to insert into the format string
1507 * Appends a formatted string onto the end of a #GString.
1508 * This function is similar to g_string_printf() except
1509 * that the text is appended to the #GString.
1512 g_string_append_printf (GString *string,
1513 const gchar *format,
1518 va_start (args, format);
1519 g_string_append_vprintf (string, format, args);
1523 #define __G_STRING_C__
1524 #include "galiasdef.c"