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 <!-- ##### SECTION Stability_Level ##### -->
22 <!-- ##### STRUCT GString ##### -->
24 The #GString struct contains the public fields of a #GString.
25 The <structfield>str</structfield> field points to the character data.
26 It may move as text is added.
27 The <structfield>len</structfield> field contains the length of the string,
28 not including the terminating nul byte.
31 The <structfield>str</structfield> field is nul-terminated and so can be used as an ordinary C
32 string. But it may be moved when text is appended or inserted into the
40 <!-- ##### FUNCTION g_string_new ##### -->
42 Creates a new #GString, initialized with the given string.
45 @init: the initial text to copy into the string.
46 @Returns: the new #GString.
49 <!-- ##### FUNCTION g_string_new_len ##### -->
51 Creates a new #GString with @len bytes of the @init buffer. Because a length is
52 provided, @init need not be nul-terminated, and can contain embedded nul bytes.
55 @init: initial contents of string.
56 @len: length of @init to use.
57 @Returns: a new #GString.
60 <!-- ##### FUNCTION g_string_sized_new ##### -->
62 Creates a new #GString, with enough space for @dfl_size bytes.
63 This is useful if you are going to add a lot of text to the string and
64 don't want it to be reallocated too often.
67 @dfl_size: the default size of the space allocated to hold the string.
68 @Returns: the new #GString.
71 <!-- ##### FUNCTION g_string_assign ##### -->
73 Copies the bytes from a string into a #GString, destroying any previous
74 contents. It is rather like the standard strcpy() function, except that
75 you do not have to worry about having enough space to copy the string.
78 @string: the destination #GString. Its current contents are destroyed.
79 @rval: the string to copy into @string
80 @Returns: the destination #GString.
81 <!-- # Unused Parameters # -->
82 @val: the string to copy into @string.
85 <!-- ##### MACRO g_string_sprintf ##### -->
87 Writes a formatted string into a #GString.
88 This is similar to the standard sprintf() function,
89 except that the #GString buffer automatically expands to contain the results.
90 The previous contents of the #GString are destroyed.
93 @Deprecated: This function has been renamed to g_string_printf().
95 @format: the string format. See the sprintf() documentation.
96 @Varargs: the parameters to insert into the format string.
99 <!-- ##### MACRO g_string_sprintfa ##### -->
101 Appends a formatted string onto the end of a #GString.
102 This function is is similar to g_string_sprintf() except that
103 the text is appended to the #GString.
106 @Deprecated: This function has been renamed to g_string_append_printf().
108 @format: the string format. See the sprintf() documentation.
109 @Varargs: the parameters to insert into the format string.
112 <!-- ##### FUNCTION g_string_printf ##### -->
114 Writes a formatted string into a #GString.
115 This is similar to the standard sprintf() function,
116 except that the #GString buffer automatically expands to contain the results.
117 The previous contents of the #GString are destroyed.
121 @format: the string format. See the printf() documentation.
122 @Varargs: the parameters to insert into the format string.
125 <!-- ##### FUNCTION g_string_append_printf ##### -->
127 Appends a formatted string onto the end of a #GString.
128 This function is is similar to g_string_printf() except that
129 the text is appended to the #GString.
133 @format: the string format. See the printf() documentation.
134 @Varargs: the parameters to insert into the format string.
137 <!-- ##### FUNCTION g_string_append ##### -->
139 Adds a string onto the end of a #GString, expanding it if necessary.
143 @val: the string to append onto the end of the #GString.
144 @Returns: the #GString.
147 <!-- ##### FUNCTION g_string_append_c ##### -->
149 Adds a byte onto the end of a #GString, expanding it if necessary.
153 @c: the byte to append onto the end of the #GString.
154 @Returns: the #GString.
157 <!-- ##### FUNCTION g_string_append_unichar ##### -->
167 <!-- ##### FUNCTION g_string_append_len ##### -->
169 Appends @len bytes of @val to @string. Because @len is provided,
170 @val may contain embedded nuls and need not be nul-terminated.
174 @val: bytes to append.
175 @len: number of bytes of @val to use.
176 @Returns: the #GString.
179 <!-- ##### FUNCTION g_string_prepend ##### -->
181 Adds a string on to the start of a #GString, expanding it if necessary.
185 @val: the string to prepend on the start of the #GString.
186 @Returns: the #GString.
189 <!-- ##### FUNCTION g_string_prepend_c ##### -->
191 Adds a byte onto the start of a #GString, expanding it if necessary.
195 @c: the byte to prepend on the start of the #GString.
196 @Returns: the #GString.
199 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
209 <!-- ##### FUNCTION g_string_prepend_len ##### -->
211 Prepends @len bytes of @val to @string. Because @len is provided,
212 @val may contain embedded nuls and need not be nul-terminated.
216 @val: bytes to prepend.
217 @len: number of bytes in @val to prepend.
218 @Returns: the #GString passed in.
221 <!-- ##### FUNCTION g_string_insert ##### -->
223 Inserts a copy of a string into a #GString, expanding it if necessary.
227 @pos: the position to insert the copy of the string.
228 @val: the string to insert.
229 @Returns: the #GString.
232 <!-- ##### FUNCTION g_string_insert_c ##### -->
234 Inserts a byte into a #GString, expanding it if necessary.
238 @pos: the position to insert the byte.
239 @c: the byte to insert.
240 @Returns: the #GString.
243 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
254 <!-- ##### FUNCTION g_string_insert_len ##### -->
256 Inserts @len bytes of @val into @string at @pos. Because @len is provided, @val
257 may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
261 @pos: position in @string where insertion should happen, or -1 for at the end.
262 @val: bytes to insert.
263 @len: number of bytes of @val to insert.
264 @Returns: the #GString.
267 <!-- ##### FUNCTION g_string_erase ##### -->
269 Removes @len bytes from a #GString, starting at position @pos.
270 The rest of the #GString is shifted down to fill the gap.
274 @pos: the position of the content to remove.
275 @len: the number of bytes to remove, or -1 to remove all
277 @Returns: the #GString.
280 <!-- ##### FUNCTION g_string_truncate ##### -->
282 Cuts off the end of the GString, leaving the first @len bytes.
286 @len: the new size of the #GString.
287 @Returns: the #GString.
290 <!-- ##### FUNCTION g_string_set_size ##### -->
300 <!-- ##### FUNCTION g_string_free ##### -->
302 Frees the memory allocated for the #GString.
303 If @free_segment is %TRUE it also frees the character data.
307 @free_segment: if %TRUE the actual character data is freed as well.
308 @Returns: the character data of @string (i.e. %NULL if @free_segment is %TRUE)
311 <!-- ##### FUNCTION g_string_up ##### -->
319 <!-- ##### FUNCTION g_string_down ##### -->
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.