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().
94 <!-- # Unused Parameters # -->
96 @format: the string format. See the sprintf() documentation.
97 @Varargs: the parameters to insert into the format string.
100 <!-- ##### MACRO g_string_sprintfa ##### -->
102 Appends a formatted string onto the end of a #GString.
103 This function is is similar to g_string_sprintf() except that
104 the text is appended to the #GString.
107 @Deprecated: This function has been renamed to g_string_append_printf().
108 <!-- # Unused Parameters # -->
110 @format: the string format. See the sprintf() documentation.
111 @Varargs: the parameters to insert into the format string.
114 <!-- ##### FUNCTION g_string_printf ##### -->
116 Writes a formatted string into a #GString.
117 This is similar to the standard sprintf() function,
118 except that the #GString buffer automatically expands to contain the results.
119 The previous contents of the #GString are destroyed.
123 @format: the string format. See the printf() documentation.
124 @Varargs: the parameters to insert into the format string.
127 <!-- ##### FUNCTION g_string_append_printf ##### -->
129 Appends a formatted string onto the end of a #GString.
130 This function is is similar to g_string_printf() except that
131 the text is appended to the #GString.
135 @format: the string format. See the printf() documentation.
136 @Varargs: the parameters to insert into the format string.
139 <!-- ##### FUNCTION g_string_append ##### -->
141 Adds a string onto the end of a #GString, expanding it if necessary.
145 @val: the string to append onto the end of the #GString.
146 @Returns: the #GString.
149 <!-- ##### FUNCTION g_string_append_c ##### -->
151 Adds a byte onto the end of a #GString, expanding it if necessary.
155 @c: the byte to append onto the end of the #GString.
156 @Returns: the #GString.
159 <!-- ##### FUNCTION g_string_append_unichar ##### -->
169 <!-- ##### FUNCTION g_string_append_len ##### -->
171 Appends @len bytes of @val to @string. Because @len is provided,
172 @val may contain embedded nuls and need not be nul-terminated.
176 @val: bytes to append.
177 @len: number of bytes of @val to use.
178 @Returns: the #GString.
181 <!-- ##### FUNCTION g_string_prepend ##### -->
183 Adds a string on to the start of a #GString, expanding it if necessary.
187 @val: the string to prepend on the start of the #GString.
188 @Returns: the #GString.
191 <!-- ##### FUNCTION g_string_prepend_c ##### -->
193 Adds a byte onto the start of a #GString, expanding it if necessary.
197 @c: the byte to prepend on the start of the #GString.
198 @Returns: the #GString.
201 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
211 <!-- ##### FUNCTION g_string_prepend_len ##### -->
213 Prepends @len bytes of @val to @string. Because @len is provided,
214 @val may contain embedded nuls and need not be nul-terminated.
218 @val: bytes to prepend.
219 @len: number of bytes in @val to prepend.
220 @Returns: the #GString passed in.
223 <!-- ##### FUNCTION g_string_insert ##### -->
225 Inserts a copy of a string into a #GString, expanding it if necessary.
229 @pos: the position to insert the copy of the string.
230 @val: the string to insert.
231 @Returns: the #GString.
234 <!-- ##### FUNCTION g_string_insert_c ##### -->
236 Inserts a byte into a #GString, expanding it if necessary.
240 @pos: the position to insert the byte.
241 @c: the byte to insert.
242 @Returns: the #GString.
245 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
256 <!-- ##### FUNCTION g_string_insert_len ##### -->
258 Inserts @len bytes of @val into @string at @pos. Because @len is provided, @val
259 may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
263 @pos: position in @string where insertion should happen, or -1 for at the end.
264 @val: bytes to insert.
265 @len: number of bytes of @val to insert.
266 @Returns: the #GString.
269 <!-- ##### FUNCTION g_string_erase ##### -->
271 Removes @len bytes from a #GString, starting at position @pos.
272 The rest of the #GString is shifted down to fill the gap.
276 @pos: the position of the content to remove.
277 @len: the number of bytes to remove, or -1 to remove all
279 @Returns: the #GString.
282 <!-- ##### FUNCTION g_string_truncate ##### -->
284 Cuts off the end of the GString, leaving the first @len bytes.
288 @len: the new size of the #GString.
289 @Returns: the #GString.
292 <!-- ##### FUNCTION g_string_set_size ##### -->
302 <!-- ##### FUNCTION g_string_free ##### -->
304 Frees the memory allocated for the #GString.
305 If @free_segment is %TRUE it also frees the character data.
309 @free_segment: if %TRUE the actual character data is freed as well.
310 @Returns: the character data of @string (i.e. %NULL if @free_segment is %TRUE)
313 <!-- ##### FUNCTION g_string_up ##### -->
321 <!-- ##### FUNCTION g_string_down ##### -->
329 <!-- ##### FUNCTION g_string_hash ##### -->
331 Creates a hash code for @str; for use with #GHashTable.
334 @str: a string to hash.
335 @Returns: hash code for @str.
338 <!-- ##### FUNCTION g_string_equal ##### -->
340 Compares two strings for equality, returning %TRUE if they are equal.
341 For use with #GHashTable.
345 @v2: another #GString.
346 @Returns: %TRUE if they strings are the same length and contain the same bytes.