1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 text buffers which grow automatically as text is added.
7 <!-- ##### SECTION Long_Description ##### -->
9 A #GString is similar to a standard C string, except that it grows automatically
10 as text is appended or inserted. Also, it stores the length of the string, so
11 can be used for binary data with embedded nul bytes.
14 <!-- ##### SECTION See_Also ##### -->
19 <!-- ##### STRUCT GString ##### -->
21 The #GString struct contains the public fields of a #GString.
22 The <structfield>str</structfield> field points to the character data.
23 It may move as text is added.
24 The <structfield>len</structfield> field contains the length of the string,
25 not including the terminating null character.
28 The str field is zero-terminated and so can be used as an ordinary C
29 string. But it may be moved when text is appended or inserted into the
37 <!-- ##### FUNCTION g_string_new ##### -->
39 Creates a new #GString, initialized with the given string.
42 @init: the initial text to copy into the string.
43 @Returns: the new #GString.
46 <!-- ##### FUNCTION g_string_new_len ##### -->
48 Creates a new #GString with @len bytes of the @init buffer. Because a length is
49 provided, @init need not be nul-terminated, and can contain embedded nul bytes.
52 @init: initial contents of string
53 @len: length of @init to use
54 @Returns: a new #GString
57 <!-- ##### FUNCTION g_string_sized_new ##### -->
59 Creates a new GString, with enough space for @dfl_size characters.
60 This is useful if you are going to add a lot of text to the string and
61 don't want it to be reallocated too often.
64 @dfl_size: the default size of the space allocated to hold the string.
65 @Returns: the new #GString.
68 <!-- ##### FUNCTION g_string_assign ##### -->
70 Copies the characters from one #GString into another, destroying any previous
71 contents. It is rather like the standard strcpy() function, except that
72 you do not have to worry about having enough space to copy the string.
75 @string: the destination #GString. Its current contents are destroyed.
76 @rval: the source #GString.
77 @Returns: the destination #GString.
80 <!-- ##### MACRO g_string_sprintf ##### -->
82 Writes a formatted string into a #GString.
83 This is similar to the standard <function>sprintf()</function> function,
84 except that the GString buffer automatically expands to contain the results.
85 The previous contents of the GString are destroyed.
88 <!-- # Unused Parameters # -->
90 @format: the string format. See the <function>sprintf()</function>
92 @Varargs: the parameters to insert into the format string.
95 <!-- ##### MACRO g_string_sprintfa ##### -->
97 Appends a formatted string onto the end of a #GString.
98 This function is is similar to g_string_sprintf() except that
99 the text is appended to the GString.
102 <!-- # Unused Parameters # -->
104 @format: the string format. See the <function>sprintf()</function>
106 @Varargs: the parameters to insert into the format string.
109 <!-- ##### FUNCTION g_string_printf ##### -->
119 <!-- ##### FUNCTION g_string_printfa ##### -->
129 <!-- ##### FUNCTION g_string_append ##### -->
131 Adds a string onto the end of a #GString, expanding it if necessary.
135 @val: the string to append onto the end of the #GString.
136 @Returns: the #GString.
139 <!-- ##### FUNCTION g_string_append_c ##### -->
141 Adds a character onto the end of a #GString, expanding it if necessary.
145 @c: the character to append onto the end of the #GString.
146 @Returns: the #GString.
149 <!-- ##### FUNCTION g_string_append_unichar ##### -->
159 <!-- ##### FUNCTION g_string_append_len ##### -->
161 Appends @len bytes of @val to @string. Because @len is provided,
162 @val may contain embedded nuls and need not be nul-terminated.
166 @val: bytes to append
167 @len: number of bytes of @val to use
168 @Returns: the #GString
171 <!-- ##### FUNCTION g_string_prepend ##### -->
173 Adds a string on to the start of a #GString, expanding it if necessary.
177 @val: the string to prepend on the start of the #GString.
178 @Returns: the #GString.
181 <!-- ##### FUNCTION g_string_prepend_c ##### -->
183 Adds a character onto the start of a #GString, expanding it if necessary.
187 @c: the character to prepend on the start of the #GString.
188 @Returns: the #GString.
191 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
201 <!-- ##### FUNCTION g_string_prepend_len ##### -->
203 Prepends @len bytes of @val to @string. Because @len is provided,
204 @val may contain embedded nuls and need not be nul-terminated.
208 @val: bytes to prepend
209 @len: number of bytes in @val to prepend
210 @Returns: the #GString passed in
213 <!-- ##### FUNCTION g_string_insert ##### -->
215 Inserts a copy of a string into a #GString, expanding it if necessary.
219 @pos: the position to insert the copy of the string.
220 @val: the string to insert.
221 @Returns: the #GString.
224 <!-- ##### FUNCTION g_string_insert_c ##### -->
226 Inserts a character into a #GString, expanding it if necessary.
230 @pos: the position to insert the character.
231 @c: the character to insert.
232 @Returns: the #GString.
235 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
246 <!-- ##### FUNCTION g_string_insert_len ##### -->
248 Inserts @len bytes of @val into @string at @pos. Because @len is provided, @val
249 may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
253 @pos: position in @string where insertion should happen, or -1 for at the end
254 @val: bytes to insert
255 @len: number of bytes of @val to insert
256 @Returns: the #GString
259 <!-- ##### FUNCTION g_string_erase ##### -->
261 Removes @len characters from a #GString, starting at position @pos.
262 The rest of the #GString is shifted down to fill the gap.
266 @pos: the position of the characters to remove.
267 @len: the number of characters to remove, or -1 to remove all
268 following characters.
269 @Returns: the #GString.
272 <!-- ##### FUNCTION g_string_truncate ##### -->
274 Cuts off the end of the GString, leaving the first @len characters.
278 @len: the new size of the #GString.
279 @Returns: the #GString.
282 <!-- ##### FUNCTION g_string_set_size ##### -->
292 <!-- ##### FUNCTION g_string_free ##### -->
294 Frees the memory allocated for the #GString.
295 If free_segment is TRUE it also frees the character data.
299 @free_segment: if TRUE the actual character data is freed as well.
303 <!-- ##### FUNCTION g_string_up ##### -->
305 Converts a #GString to upper case.
309 @Returns: the #GString.
312 <!-- ##### FUNCTION g_string_down ##### -->
314 Converts a #GString to lower case.
318 @Returns: the #GString.
321 <!-- ##### FUNCTION g_string_hash ##### -->
323 Creates a hash code for @str; for use with #GHashTable.
326 @str: a string to hash
327 @Returns: hash code for @str
330 <!-- ##### FUNCTION g_string_equal ##### -->
332 Compares two strings for equality, returning %TRUE if they are equal.
333 For use with #GHashTable.
337 @v2: another #GString
338 @Returns: %TRUE if they strings are the same length and contain the same bytes