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.
125 * This function implements the widely used "djb" hash apparently posted
126 * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit
127 * unsigned hash value starts at 5381 and for each byte 'c' in the
128 * string, is updated: <literal>hash = hash * 33 + c</literal>. This
129 * function uses the signed value of each byte.
131 * It can be passed to g_hash_table_new() as the @hash_func parameter,
132 * when using strings as keys in a #GHashTable.
134 * Returns: a hash value corresponding to the key
137 g_str_hash (gconstpointer v)
139 const signed char *p;
142 for (p = v; *p != '\0'; p++)
143 h = (h << 5) + h + *p;
148 #define MY_MAXSIZE ((gsize)-1)
151 nearest_power (gsize base, gsize num)
153 if (num > MY_MAXSIZE / 2)
172 * g_string_chunk_new:
173 * @size: the default size of the blocks of memory which are
174 * allocated to store the strings. If a particular string
175 * is larger than this default size, a larger block of
176 * memory will be allocated for it.
178 * Creates a new #GStringChunk.
180 * Returns: a new #GStringChunk
183 g_string_chunk_new (gsize size)
185 GStringChunk *new_chunk = g_new (GStringChunk, 1);
186 gsize actual_size = 1;
188 actual_size = nearest_power (1, size);
190 new_chunk->const_table = NULL;
191 new_chunk->storage_list = NULL;
192 new_chunk->storage_next = actual_size;
193 new_chunk->default_size = actual_size;
194 new_chunk->this_size = actual_size;
200 * g_string_chunk_free:
201 * @chunk: a #GStringChunk
203 * Frees all memory allocated by the #GStringChunk.
204 * After calling g_string_chunk_free() it is not safe to
205 * access any of the strings which were contained within it.
208 g_string_chunk_free (GStringChunk *chunk)
212 g_return_if_fail (chunk != NULL);
214 if (chunk->storage_list)
216 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
217 g_free (tmp_list->data);
219 g_slist_free (chunk->storage_list);
222 if (chunk->const_table)
223 g_hash_table_destroy (chunk->const_table);
229 * g_string_chunk_clear:
230 * @chunk: a #GStringChunk
232 * Frees all strings contained within the #GStringChunk.
233 * After calling g_string_chunk_clear() it is not safe to
234 * access any of the strings which were contained within it.
239 g_string_chunk_clear (GStringChunk *chunk)
243 g_return_if_fail (chunk != NULL);
245 if (chunk->storage_list)
247 for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
248 g_free (tmp_list->data);
250 g_slist_free (chunk->storage_list);
252 chunk->storage_list = NULL;
253 chunk->storage_next = chunk->default_size;
254 chunk->this_size = chunk->default_size;
257 if (chunk->const_table)
258 g_hash_table_remove_all (chunk->const_table);
262 * g_string_chunk_insert:
263 * @chunk: a #GStringChunk
264 * @string: the string to add
266 * Adds a copy of @string to the #GStringChunk.
267 * It returns a pointer to the new copy of the string
268 * in the #GStringChunk. The characters in the string
269 * can be changed, if necessary, though you should not
270 * change anything after the end of the string.
272 * Unlike g_string_chunk_insert_const(), this function
273 * does not check for duplicates. Also strings added
274 * with g_string_chunk_insert() will not be searched
275 * by g_string_chunk_insert_const() when looking for
278 * Returns: a pointer to the copy of @string within
282 g_string_chunk_insert (GStringChunk *chunk,
285 g_return_val_if_fail (chunk != NULL, NULL);
287 return g_string_chunk_insert_len (chunk, string, -1);
291 * g_string_chunk_insert_const:
292 * @chunk: a #GStringChunk
293 * @string: the string to add
295 * Adds a copy of @string to the #GStringChunk, unless the same
296 * string has already been added to the #GStringChunk with
297 * g_string_chunk_insert_const().
299 * This function is useful if you need to copy a large number
300 * of strings but do not want to waste space storing duplicates.
301 * But you must remember that there may be several pointers to
302 * the same string, and so any changes made to the strings
303 * should be done very carefully.
305 * Note that g_string_chunk_insert_const() will not return a
306 * pointer to a string added with g_string_chunk_insert(), even
309 * Returns: a pointer to the new or existing copy of @string
310 * within the #GStringChunk
313 g_string_chunk_insert_const (GStringChunk *chunk,
318 g_return_val_if_fail (chunk != NULL, NULL);
320 if (!chunk->const_table)
321 chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal);
323 lookup = (char*) g_hash_table_lookup (chunk->const_table, (gchar *)string);
327 lookup = g_string_chunk_insert (chunk, string);
328 g_hash_table_insert (chunk->const_table, lookup, lookup);
335 * g_string_chunk_insert_len:
336 * @chunk: a #GStringChunk
337 * @string: bytes to insert
338 * @len: number of bytes of @string to insert, or -1 to insert a
339 * nul-terminated string
341 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
342 * The copy is nul-terminated.
344 * Since this function does not stop at nul bytes, it is the caller's
345 * responsibility to ensure that @string has at least @len addressable
348 * The characters in the returned string can be changed, if necessary,
349 * though you should not change anything after the end of the string.
351 * Return value: a pointer to the copy of @string within the #GStringChunk
356 g_string_chunk_insert_len (GStringChunk *chunk,
363 g_return_val_if_fail (chunk != NULL, NULL);
366 size = strlen (string);
370 if ((chunk->storage_next + size + 1) > chunk->this_size)
372 gsize new_size = nearest_power (chunk->default_size, size + 1);
374 chunk->storage_list = g_slist_prepend (chunk->storage_list,
375 g_new (gchar, new_size));
377 chunk->this_size = new_size;
378 chunk->storage_next = 0;
381 pos = ((gchar *) chunk->storage_list->data) + chunk->storage_next;
383 *(pos + size) = '\0';
385 memcpy (pos, string, size);
387 chunk->storage_next += size + 1;
395 g_string_maybe_expand (GString *string,
398 if (string->len + len >= string->allocated_len)
400 string->allocated_len = nearest_power (1, string->len + len + 1);
401 string->str = g_realloc (string->str, string->allocated_len);
406 * g_string_sized_new:
407 * @dfl_size: the default size of the space allocated to
410 * Creates a new #GString, with enough space for @dfl_size
411 * bytes. This is useful if you are going to add a lot of
412 * text to the string and don't want it to be reallocated
415 * Returns: the new #GString
418 g_string_sized_new (gsize dfl_size)
420 GString *string = g_slice_new (GString);
422 string->allocated_len = 0;
426 g_string_maybe_expand (string, MAX (dfl_size, 2));
434 * @init: the initial text to copy into the string
436 * Creates a new #GString, initialized with the given string.
438 * Returns: the new #GString
441 g_string_new (const gchar *init)
445 if (init == NULL || *init == '\0')
446 string = g_string_sized_new (2);
452 string = g_string_sized_new (len + 2);
454 g_string_append_len (string, init, len);
462 * @init: initial contents of the string
463 * @len: length of @init to use
465 * Creates a new #GString with @len bytes of the @init buffer.
466 * Because a length is provided, @init need not be nul-terminated,
467 * and can contain embedded nul bytes.
469 * Since this function does not stop at nul bytes, it is the caller's
470 * responsibility to ensure that @init has at least @len addressable
473 * Returns: a new #GString
476 g_string_new_len (const gchar *init,
482 return g_string_new (init);
485 string = g_string_sized_new (len);
488 g_string_append_len (string, init, len);
496 * @string: a #GString
497 * @free_segment: if %TRUE, the actual character data is freed as well
499 * Frees the memory allocated for the #GString.
500 * If @free_segment is %TRUE it also frees the character data. If
501 * it's %FALSE, the caller gains ownership of the buffer and must
502 * free it after use with g_free().
504 * Returns: the character data of @string
505 * (i.e. %NULL if @free_segment is %TRUE)
508 g_string_free (GString *string,
509 gboolean free_segment)
513 g_return_val_if_fail (string != NULL, NULL);
517 g_free (string->str);
521 segment = string->str;
523 g_slice_free (GString, string);
531 * @v2: another #GString
533 * Compares two strings for equality, returning %TRUE if they are equal.
534 * For use with #GHashTable.
536 * Returns: %TRUE if they strings are the same length and contain the
540 g_string_equal (const GString *v,
544 GString *string1 = (GString *) v;
545 GString *string2 = (GString *) v2;
546 gsize i = string1->len;
548 if (i != string2->len)
566 * @str: a string to hash
568 * Creates a hash code for @str; for use with #GHashTable.
570 * Returns: hash code for @str
573 g_string_hash (const GString *str)
575 const gchar *p = str->str;
579 /* 31 bit hash function */
582 h = (h << 5) - h + *p;
591 * @string: the destination #GString. Its current contents
593 * @rval: the string to copy into @string
595 * Copies the bytes from a string into a #GString,
596 * destroying any previous contents. It is rather like
597 * the standard strcpy() function, except that you do not
598 * have to worry about having enough space to copy the string.
603 g_string_assign (GString *string,
606 g_return_val_if_fail (string != NULL, NULL);
607 g_return_val_if_fail (rval != NULL, string);
609 /* Make sure assigning to itself doesn't corrupt the string. */
610 if (string->str != rval)
612 /* Assigning from substring should be ok, since
613 * g_string_truncate() does not reallocate.
615 g_string_truncate (string, 0);
616 g_string_append (string, rval);
624 * @string: a #GString
625 * @len: the new size of @string
627 * Cuts off the end of the GString, leaving the first @len bytes.
632 g_string_truncate (GString *string,
635 g_return_val_if_fail (string != NULL, NULL);
637 string->len = MIN (len, string->len);
638 string->str[string->len] = 0;
645 * @string: a #GString
646 * @len: the new length
648 * Sets the length of a #GString. If the length is less than
649 * the current length, the string will be truncated. If the
650 * length is greater than the current length, the contents
651 * of the newly added area are undefined. (However, as
652 * always, string->str[string->len] will be a nul byte.)
654 * Return value: @string
657 g_string_set_size (GString *string,
660 g_return_val_if_fail (string != NULL, NULL);
662 if (len >= string->allocated_len)
663 g_string_maybe_expand (string, len - string->len);
666 string->str[len] = 0;
672 * g_string_insert_len:
673 * @string: a #GString
674 * @pos: position in @string where insertion should
675 * happen, or -1 for at the end
676 * @val: bytes to insert
677 * @len: number of bytes of @val to insert
679 * Inserts @len bytes of @val into @string at @pos.
680 * Because @len is provided, @val may contain embedded
681 * nuls and need not be nul-terminated. If @pos is -1,
682 * bytes are inserted at the end of the string.
684 * Since this function does not stop at nul bytes, it is
685 * the caller's responsibility to ensure that @val has at
686 * least @len addressable bytes.
691 g_string_insert_len (GString *string,
696 g_return_val_if_fail (string != NULL, NULL);
697 g_return_val_if_fail (len == 0 || val != NULL, string);
708 g_return_val_if_fail (pos <= string->len, string);
710 /* Check whether val represents a substring of string.
711 * This test probably violates chapter and verse of the C standards,
712 * since ">=" and "<=" are only valid when val really is a substring.
713 * In practice, it will work on modern archs.
715 if (val >= string->str && val <= string->str + string->len)
717 gsize offset = val - string->str;
720 g_string_maybe_expand (string, len);
721 val = string->str + offset;
722 /* At this point, val is valid again. */
724 /* Open up space where we are going to insert. */
725 if (pos < string->len)
726 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
728 /* Move the source part before the gap, if any. */
731 precount = MIN (len, pos - offset);
732 memcpy (string->str + pos, val, precount);
735 /* Move the source part after the gap, if any. */
737 memcpy (string->str + pos + precount,
738 val + /* Already moved: */ precount + /* Space opened up: */ len,
743 g_string_maybe_expand (string, len);
745 /* If we aren't appending at the end, move a hunk
746 * of the old string to the end, opening up space
748 if (pos < string->len)
749 g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
751 /* insert the new string */
753 string->str[pos] = *val;
755 memcpy (string->str + pos, val, len);
760 string->str[string->len] = 0;
765 #define SUB_DELIM_CHARS "!$&'()*+,;="
769 const char *reserved_chars_allowed)
771 if (g_ascii_isalnum (c) ||
778 if (reserved_chars_allowed &&
779 strchr (reserved_chars_allowed, c) != NULL)
786 gunichar_ok (gunichar c)
789 (c != (gunichar) -2) &&
790 (c != (gunichar) -1);
794 * g_string_append_uri_escaped:
795 * @string: a #GString
796 * @unescaped: a string
797 * @reserved_chars_allowed: a string of reserved characters allowed
798 * to be used, or %NULL
799 * @allow_utf8: set %TRUE if the escaped string may include UTF8 characters
801 * Appends @unescaped to @string, escaped any characters that
802 * are reserved in URIs using URI-style escape sequences.
809 g_string_append_uri_escaped (GString *string,
810 const gchar *unescaped,
811 const gchar *reserved_chars_allowed,
816 static const gchar hex[16] = "0123456789ABCDEF";
818 g_return_val_if_fail (string != NULL, NULL);
819 g_return_val_if_fail (unescaped != NULL, NULL);
821 end = unescaped + strlen (unescaped);
823 while ((c = *unescaped) != 0)
825 if (c >= 0x80 && allow_utf8 &&
826 gunichar_ok (g_utf8_get_char_validated (unescaped, end - unescaped)))
828 int len = g_utf8_skip [c];
829 g_string_append_len (string, unescaped, len);
832 else if (is_valid (c, reserved_chars_allowed))
834 g_string_append_c (string, c);
839 g_string_append_c (string, '%');
840 g_string_append_c (string, hex[((guchar)c) >> 4]);
841 g_string_append_c (string, hex[((guchar)c) & 0xf]);
851 * @string: a #GString
852 * @val: the string to append onto the end of @string
854 * Adds a string onto the end of a #GString, expanding
860 g_string_append (GString *string,
863 g_return_val_if_fail (string != NULL, NULL);
864 g_return_val_if_fail (val != NULL, string);
866 return g_string_insert_len (string, -1, val, -1);
870 * g_string_append_len:
871 * @string: a #GString
872 * @val: bytes to append
873 * @len: number of bytes of @val to use
875 * Appends @len bytes of @val to @string. Because @len is
876 * provided, @val may contain embedded nuls and need not
879 * Since this function does not stop at nul bytes, it is
880 * the caller's responsibility to ensure that @val has at
881 * least @len addressable bytes.
886 g_string_append_len (GString *string,
890 g_return_val_if_fail (string != NULL, NULL);
891 g_return_val_if_fail (len == 0 || val != NULL, string);
893 return g_string_insert_len (string, -1, val, len);
898 * @string: a #GString
899 * @c: the byte to append onto the end of @string
901 * Adds a byte onto the end of a #GString, expanding
906 #undef g_string_append_c
908 g_string_append_c (GString *string,
911 g_return_val_if_fail (string != NULL, NULL);
913 return g_string_insert_c (string, -1, c);
917 * g_string_append_unichar:
918 * @string: a #GString
919 * @wc: a Unicode character
921 * Converts a Unicode character into UTF-8, and appends it
924 * Return value: @string
927 g_string_append_unichar (GString *string,
930 g_return_val_if_fail (string != NULL, NULL);
932 return g_string_insert_unichar (string, -1, wc);
937 * @string: a #GString
938 * @val: the string to prepend on the start of @string
940 * Adds a string on to the start of a #GString,
941 * expanding it if necessary.
946 g_string_prepend (GString *string,
949 g_return_val_if_fail (string != NULL, NULL);
950 g_return_val_if_fail (val != NULL, string);
952 return g_string_insert_len (string, 0, val, -1);
956 * g_string_prepend_len:
957 * @string: a #GString
958 * @val: bytes to prepend
959 * @len: number of bytes in @val to prepend
961 * Prepends @len bytes of @val to @string.
962 * Because @len is provided, @val may contain
963 * embedded nuls and need not be nul-terminated.
965 * Since this function does not stop at nul bytes,
966 * it is the caller's responsibility to ensure that
967 * @val has at least @len addressable bytes.
972 g_string_prepend_len (GString *string,
976 g_return_val_if_fail (string != NULL, NULL);
977 g_return_val_if_fail (val != NULL, string);
979 return g_string_insert_len (string, 0, val, len);
983 * g_string_prepend_c:
984 * @string: a #GString
985 * @c: the byte to prepend on the start of the #GString
987 * Adds a byte onto the start of a #GString,
988 * expanding it if necessary.
993 g_string_prepend_c (GString *string,
996 g_return_val_if_fail (string != NULL, NULL);
998 return g_string_insert_c (string, 0, c);
1002 * g_string_prepend_unichar:
1003 * @string: a #GString
1004 * @wc: a Unicode character
1006 * Converts a Unicode character into UTF-8, and prepends it
1009 * Return value: @string
1012 g_string_prepend_unichar (GString *string,
1015 g_return_val_if_fail (string != NULL, NULL);
1017 return g_string_insert_unichar (string, 0, wc);
1022 * @string: a #GString
1023 * @pos: the position to insert the copy of the string
1024 * @val: the string to insert
1026 * Inserts a copy of a string into a #GString,
1027 * expanding it if necessary.
1032 g_string_insert (GString *string,
1036 g_return_val_if_fail (string != NULL, NULL);
1037 g_return_val_if_fail (val != NULL, string);
1040 g_return_val_if_fail (pos <= string->len, string);
1042 return g_string_insert_len (string, pos, val, -1);
1046 * g_string_insert_c:
1047 * @string: a #GString
1048 * @pos: the position to insert the byte
1049 * @c: the byte to insert
1051 * Inserts a byte into a #GString, expanding it if necessary.
1056 g_string_insert_c (GString *string,
1060 g_return_val_if_fail (string != NULL, NULL);
1062 g_string_maybe_expand (string, 1);
1067 g_return_val_if_fail (pos <= string->len, string);
1069 /* If not just an append, move the old stuff */
1070 if (pos < string->len)
1071 g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
1073 string->str[pos] = c;
1077 string->str[string->len] = 0;
1083 * g_string_insert_unichar:
1084 * @string: a #GString
1085 * @pos: the position at which to insert character, or -1
1086 * to append at the end of the string
1087 * @wc: a Unicode character
1089 * Converts a Unicode character into UTF-8, and insert it
1090 * into the string at the given position.
1092 * Return value: @string
1095 g_string_insert_unichar (GString *string,
1099 gint charlen, first, i;
1102 g_return_val_if_fail (string != NULL, NULL);
1104 /* Code copied from g_unichar_to_utf() */
1110 else if (wc < 0x800)
1115 else if (wc < 0x10000)
1120 else if (wc < 0x200000)
1125 else if (wc < 0x4000000)
1135 /* End of copied code */
1137 g_string_maybe_expand (string, charlen);
1142 g_return_val_if_fail (pos <= string->len, string);
1144 /* If not just an append, move the old stuff */
1145 if (pos < string->len)
1146 g_memmove (string->str + pos + charlen, string->str + pos, string->len - pos);
1148 dest = string->str + pos;
1149 /* Code copied from g_unichar_to_utf() */
1150 for (i = charlen - 1; i > 0; --i)
1152 dest[i] = (wc & 0x3f) | 0x80;
1155 dest[0] = wc | first;
1156 /* End of copied code */
1158 string->len += charlen;
1160 string->str[string->len] = 0;
1166 * g_string_overwrite:
1167 * @string: a #GString
1168 * @pos: the position at which to start overwriting
1169 * @val: the string that will overwrite the @string starting at @pos
1171 * Overwrites part of a string, lengthening it if necessary.
1173 * Return value: @string
1178 g_string_overwrite (GString *string,
1182 g_return_val_if_fail (val != NULL, string);
1183 return g_string_overwrite_len (string, pos, val, strlen (val));
1187 * g_string_overwrite_len:
1188 * @string: a #GString
1189 * @pos: the position at which to start overwriting
1190 * @val: the string that will overwrite the @string starting at @pos
1191 * @len: the number of bytes to write from @val
1193 * Overwrites part of a string, lengthening it if necessary.
1194 * This function will work with embedded nuls.
1196 * Return value: @string
1201 g_string_overwrite_len (GString *string,
1208 g_return_val_if_fail (string != NULL, NULL);
1213 g_return_val_if_fail (val != NULL, string);
1214 g_return_val_if_fail (pos <= string->len, string);
1221 if (end > string->len)
1222 g_string_maybe_expand (string, end - string->len);
1224 memcpy (string->str + pos, val, len);
1226 if (end > string->len)
1228 string->str[end] = '\0';
1237 * @string: a #GString
1238 * @pos: the position of the content to remove
1239 * @len: the number of bytes to remove, or -1 to remove all
1242 * Removes @len bytes from a #GString, starting at position @pos.
1243 * The rest of the #GString is shifted down to fill the gap.
1248 g_string_erase (GString *string,
1252 g_return_val_if_fail (string != NULL, NULL);
1253 g_return_val_if_fail (pos >= 0, string);
1254 g_return_val_if_fail (pos <= string->len, string);
1257 len = string->len - pos;
1260 g_return_val_if_fail (pos + len <= string->len, string);
1262 if (pos + len < string->len)
1263 g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
1268 string->str[string->len] = 0;
1274 * g_string_ascii_down:
1275 * @string: a GString
1277 * Converts all uppercase ASCII letters to lowercase ASCII letters.
1279 * Return value: passed-in @string pointer, with all the
1280 * uppercase characters converted to lowercase in place,
1281 * with semantics that exactly match g_ascii_tolower().
1284 g_string_ascii_down (GString *string)
1289 g_return_val_if_fail (string != NULL, NULL);
1296 *s = g_ascii_tolower (*s);
1305 * g_string_ascii_up:
1306 * @string: a GString
1308 * Converts all lowercase ASCII letters to uppercase ASCII letters.
1310 * Return value: passed-in @string pointer, with all the
1311 * lowercase characters converted to uppercase in place,
1312 * with semantics that exactly match g_ascii_toupper().
1315 g_string_ascii_up (GString *string)
1320 g_return_val_if_fail (string != NULL, NULL);
1327 *s = g_ascii_toupper (*s);
1337 * @string: a #GString
1339 * Converts a #GString to lowercase.
1341 * Returns: the #GString
1343 * Deprecated:2.2: This function uses the locale-specific
1344 * tolower() function, which is almost never the right thing.
1345 * Use g_string_ascii_down() or g_utf8_strdown() instead.
1348 g_string_down (GString *string)
1353 g_return_val_if_fail (string != NULL, NULL);
1356 s = (guchar *) string->str;
1371 * @string: a #GString
1373 * Converts a #GString to uppercase.
1375 * Return value: @string
1377 * Deprecated:2.2: This function uses the locale-specific
1378 * toupper() function, which is almost never the right thing.
1379 * Use g_string_ascii_up() or g_utf8_strup() instead.
1382 g_string_up (GString *string)
1387 g_return_val_if_fail (string != NULL, NULL);
1390 s = (guchar *) string->str;
1404 * g_string_append_vprintf:
1405 * @string: a #GString
1406 * @format: the string format. See the printf() documentation
1407 * @args: the list of arguments to insert in the output
1409 * Appends a formatted string onto the end of a #GString.
1410 * This function is similar to g_string_append_printf()
1411 * except that the arguments to the format string are passed
1417 g_string_append_vprintf (GString *string,
1418 const gchar *format,
1424 g_return_if_fail (string != NULL);
1425 g_return_if_fail (format != NULL);
1427 len = g_vasprintf (&buf, format, args);
1431 g_string_maybe_expand (string, len);
1432 memcpy (string->str + string->len, buf, len + 1);
1440 * @string: a #GString
1441 * @format: the string format. See the printf() documentation
1442 * @args: the parameters to insert into the format string
1444 * Writes a formatted string into a #GString.
1445 * This function is similar to g_string_printf() except that
1446 * the arguments to the format string are passed as a va_list.
1451 g_string_vprintf (GString *string,
1452 const gchar *format,
1455 g_string_truncate (string, 0);
1456 g_string_append_vprintf (string, format, args);
1461 * @string: a #GString
1462 * @format: the string format. See the sprintf() documentation
1463 * @...: the parameters to insert into the format string
1465 * Writes a formatted string into a #GString.
1466 * This is similar to the standard sprintf() function,
1467 * except that the #GString buffer automatically expands
1468 * to contain the results. The previous contents of the
1469 * #GString are destroyed.
1471 * Deprecated: This function has been renamed to g_string_printf().
1476 * @string: a #GString
1477 * @format: the string format. See the printf() documentation
1478 * @...: the parameters to insert into the format string
1480 * Writes a formatted string into a #GString.
1481 * This is similar to the standard sprintf() function,
1482 * except that the #GString buffer automatically expands
1483 * to contain the results. The previous contents of the
1484 * #GString are destroyed.
1487 g_string_printf (GString *string,
1488 const gchar *format,
1493 g_string_truncate (string, 0);
1495 va_start (args, format);
1496 g_string_append_vprintf (string, format, args);
1501 * g_string_sprintfa:
1502 * @string: a #GString
1503 * @format: the string format. See the sprintf() documentation
1504 * @...: the parameters to insert into the format string
1506 * Appends a formatted string onto the end of a #GString.
1507 * This function is similar to g_string_sprintf() except that
1508 * the text is appended to the #GString.
1510 * Deprecated: This function has been renamed to g_string_append_printf()
1514 * g_string_append_printf:
1515 * @string: a #GString
1516 * @format: the string format. See the printf() documentation
1517 * @...: the parameters to insert into the format string
1519 * Appends a formatted string onto the end of a #GString.
1520 * This function is similar to g_string_printf() except
1521 * that the text is appended to the #GString.
1524 g_string_append_printf (GString *string,
1525 const gchar *format,
1530 va_start (args, format);
1531 g_string_append_vprintf (string, format, args);