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 nul character.
28 The <structfield>str</structfield> field is nul-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 <function>strcpy()</function> 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 ##### -->
111 Writes a formatted string into a #GString.
112 This is similar to the standard <function>sprintf()</function> function,
113 except that the #GString buffer automatically expands to contain the results.
114 The previous contents of the #GString are destroyed.
118 @format: the string format. See the <function>sprintf()</function>
120 @Varargs: the parameters to insert into the format string.
123 <!-- ##### FUNCTION g_string_printfa ##### -->
125 Appends a formatted string onto the end of a #GString.
126 This function is is similar to g_string_sprintf() except that
127 the text is appended to the #GString.
131 @format: the string format. See the <function>sprintf()</function>
133 @Varargs: the parameters to insert into the format string.
136 <!-- ##### FUNCTION g_string_append ##### -->
138 Adds a string onto the end of a #GString, expanding it if necessary.
142 @val: the string to append onto the end of the #GString.
143 @Returns: the #GString.
146 <!-- ##### FUNCTION g_string_append_c ##### -->
148 Adds a character onto the end of a #GString, expanding it if necessary.
152 @c: the character to append onto the end of the #GString.
153 @Returns: the #GString.
156 <!-- ##### FUNCTION g_string_append_unichar ##### -->
166 <!-- ##### FUNCTION g_string_append_len ##### -->
168 Appends @len bytes of @val to @string. Because @len is provided,
169 @val may contain embedded nuls and need not be nul-terminated.
173 @val: bytes to append.
174 @len: number of bytes of @val to use.
175 @Returns: the #GString.
178 <!-- ##### FUNCTION g_string_prepend ##### -->
180 Adds a string on to the start of a #GString, expanding it if necessary.
184 @val: the string to prepend on the start of the #GString.
185 @Returns: the #GString.
188 <!-- ##### FUNCTION g_string_prepend_c ##### -->
190 Adds a character onto the start of a #GString, expanding it if necessary.
194 @c: the character to prepend on the start of the #GString.
195 @Returns: the #GString.
198 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
208 <!-- ##### FUNCTION g_string_prepend_len ##### -->
210 Prepends @len bytes of @val to @string. Because @len is provided,
211 @val may contain embedded nuls and need not be nul-terminated.
215 @val: bytes to prepend.
216 @len: number of bytes in @val to prepend.
217 @Returns: the #GString passed in.
220 <!-- ##### FUNCTION g_string_insert ##### -->
222 Inserts a copy of a string into a #GString, expanding it if necessary.
226 @pos: the position to insert the copy of the string.
227 @val: the string to insert.
228 @Returns: the #GString.
231 <!-- ##### FUNCTION g_string_insert_c ##### -->
233 Inserts a character into a #GString, expanding it if necessary.
237 @pos: the position to insert the character.
238 @c: the character to insert.
239 @Returns: the #GString.
242 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
253 <!-- ##### FUNCTION g_string_insert_len ##### -->
255 Inserts @len bytes of @val into @string at @pos. Because @len is provided, @val
256 may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
260 @pos: position in @string where insertion should happen, or -1 for at the end.
261 @val: bytes to insert.
262 @len: number of bytes of @val to insert.
263 @Returns: the #GString.
266 <!-- ##### FUNCTION g_string_erase ##### -->
268 Removes @len characters from a #GString, starting at position @pos.
269 The rest of the #GString is shifted down to fill the gap.
273 @pos: the position of the characters to remove.
274 @len: the number of characters to remove, or -1 to remove all
275 following characters.
276 @Returns: the #GString.
279 <!-- ##### FUNCTION g_string_truncate ##### -->
281 Cuts off the end of the GString, leaving the first @len characters.
285 @len: the new size of the #GString.
286 @Returns: the #GString.
289 <!-- ##### FUNCTION g_string_set_size ##### -->
299 <!-- ##### FUNCTION g_string_free ##### -->
301 Frees the memory allocated for the #GString.
302 If @free_segment is %TRUE it also frees the character data.
306 @free_segment: if %TRUE the actual character data is freed as well.
309 <!-- ##### FUNCTION g_string_up ##### -->
311 Converts a #GString to upper case.
315 @Returns: the #GString.
318 <!-- ##### FUNCTION g_string_down ##### -->
320 Converts a #GString to lower case.
324 @Returns: the #GString.
327 <!-- ##### FUNCTION g_string_hash ##### -->
329 Creates a hash code for @str; for use with #GHashTable.
332 @str: a string to hash.
333 @Returns: hash code for @str.
336 <!-- ##### FUNCTION g_string_equal ##### -->
338 Compares two strings for equality, returning %TRUE if they are equal.
339 For use with #GHashTable.
343 @v2: another #GString.
344 @Returns: %TRUE if they strings are the same length and contain the same bytes.