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
10 automatically as text is appended or inserted.
13 The space allocated for the string is always a power of two, so as the
14 string grows it will occupy 2, 4, 8, 16, 32, 64, 128 etc. characters.
17 <!-- ##### SECTION See_Also ##### -->
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 null character.
31 The str field is zero-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
39 <!-- ##### FUNCTION g_string_new ##### -->
41 Creates a new #GString, initialized with the given string.
44 @init: the initial text to copy into the string.
45 @Returns: the new #GString.
48 <!-- ##### FUNCTION g_string_sized_new ##### -->
50 Creates a new GString, with enough space for @dfl_size characters.
51 This is useful if you are going to add a lot of text to the string and
52 don't want it to be reallocated too often.
55 @dfl_size: the default size of the space allocated to hold the string.
56 @Returns: the new #GString.
59 <!-- ##### FUNCTION g_string_assign ##### -->
61 Copies the characters from one #GString into another, destroying any previous
62 contents. It is rather like the standard strcpy() function, except that
63 you do not have to worry about having enough space to copy the string.
67 @rval: the source #GString.
68 @Returns: the destination #GString.
69 <!-- # Unused Parameters # -->
70 @lval: the destination #GString. Its current contents are destroyed.
73 <!-- ##### FUNCTION g_string_sprintf ##### -->
75 Writes a formatted string into a #GString.
76 This is similar to the standard <function>sprintf()</function> function,
77 except that the GString buffer automatically expands to contain the results.
78 The previous contents of the GString are destroyed.
82 @format: the string format. See the <function>sprintf()</function>
84 @Varargs: the parameters to insert into the format string.
87 <!-- ##### FUNCTION g_string_sprintfa ##### -->
89 Appends a formatted string onto the end of a #GString.
90 This function is is similar to g_string_sprintf() except that
91 the text is appended to the GString.
95 @format: the string format. See the <function>sprintf()</function>
97 @Varargs: the parameters to insert into the format string.
100 <!-- ##### FUNCTION g_string_append ##### -->
102 Adds a string onto the end of a #GString, expanding it if necessary.
106 @val: the string to append onto the end of the #GString.
107 @Returns: the #GString.
110 <!-- ##### FUNCTION g_string_append_c ##### -->
112 Adds a character onto the end of a #GString, expanding it if necessary.
116 @c: the character to append onto the end of the #GString.
117 @Returns: the #GString.
120 <!-- ##### FUNCTION g_string_append_len ##### -->
131 <!-- ##### FUNCTION g_string_prepend ##### -->
133 Adds a string on to the start of a #GString, expanding it if necessary.
137 @val: the string to prepend on the start of the #GString.
138 @Returns: the #GString.
141 <!-- ##### FUNCTION g_string_prepend_c ##### -->
143 Adds a character onto the start of a #GString, expanding it if necessary.
147 @c: the character to prepend on the start of the #GString.
148 @Returns: the #GString.
151 <!-- ##### FUNCTION g_string_prepend_len ##### -->
162 <!-- ##### FUNCTION g_string_insert ##### -->
164 Inserts a copy of a string into a #GString, expanding it if necessary.
168 @pos: the position to insert the copy of the string.
169 @val: the string to insert.
170 @Returns: the #GString.
173 <!-- ##### FUNCTION g_string_insert_c ##### -->
175 Inserts a character into a #GString, expanding it if necessary.
179 @pos: the position to insert the character.
180 @c: the character to insert.
181 @Returns: the #GString.
184 <!-- ##### FUNCTION g_string_insert_len ##### -->
196 <!-- ##### FUNCTION g_string_erase ##### -->
198 Removes @len characters from a #GString, starting at position @pos.
199 The rest of the #GString is shifted down to fill the gap.
203 @pos: the position of the characters to remove.
204 @len: the number of characters to remove.
205 @Returns: the #GString.
208 <!-- ##### FUNCTION g_string_truncate ##### -->
210 Cuts off the end of the GString, leaving the first @len characters.
214 @len: the new size of the #GString.
215 @Returns: the #GString.
218 <!-- ##### FUNCTION g_string_free ##### -->
220 Frees the memory allocated for the #GString.
221 If free_segment is TRUE it also frees the character data.
225 @free_segment: if TRUE the actual character data is freed as well.
229 <!-- ##### FUNCTION g_string_up ##### -->
231 Converts a #GString to upper case.
235 @Returns: the #GString.
238 <!-- ##### FUNCTION g_string_down ##### -->
240 Converts a #GString to lower case.
244 @Returns: the #GString.
247 <!-- ##### FUNCTION g_string_hash ##### -->
256 <!-- ##### FUNCTION g_string_equal ##### -->