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
36 <!-- ##### FUNCTION g_string_new ##### -->
38 Creates a new #GString, initialized with the given string.
41 @init: the initial text to copy into the string.
42 @Returns: the new #GString.
45 <!-- ##### FUNCTION g_string_new_len ##### -->
47 Creates a new #GString with @len bytes of the @init buffer. Because a length is
48 provided, @init need not be nul-terminated, and can contain embedded nul bytes.
51 @init: initial contents of string
52 @len: length of @init to use
53 @Returns: a new #GString
56 <!-- ##### FUNCTION g_string_sized_new ##### -->
58 Creates a new GString, with enough space for @dfl_size characters.
59 This is useful if you are going to add a lot of text to the string and
60 don't want it to be reallocated too often.
63 @dfl_size: the default size of the space allocated to hold the string.
64 @Returns: the new #GString.
67 <!-- ##### FUNCTION g_string_assign ##### -->
69 Copies the characters from one #GString into another, destroying any previous
70 contents. It is rather like the standard strcpy() function, except that
71 you do not have to worry about having enough space to copy the string.
74 @string: the destination #GString. Its current contents are destroyed.
75 @rval: the source #GString.
76 @Returns: the destination #GString.
79 <!-- ##### MACRO g_string_sprintf ##### -->
81 Writes a formatted string into a #GString.
82 This is similar to the standard <function>sprintf()</function> function,
83 except that the GString buffer automatically expands to contain the results.
84 The previous contents of the GString are destroyed.
87 <!-- # Unused Parameters # -->
89 @format: the string format. See the <function>sprintf()</function>
91 @Varargs: the parameters to insert into the format string.
94 <!-- ##### MACRO g_string_sprintfa ##### -->
96 Appends a formatted string onto the end of a #GString.
97 This function is is similar to g_string_sprintf() except that
98 the text is appended to the GString.
101 <!-- # Unused Parameters # -->
103 @format: the string format. See the <function>sprintf()</function>
105 @Varargs: the parameters to insert into the format string.
108 <!-- ##### FUNCTION g_string_append ##### -->
110 Adds a string onto the end of a #GString, expanding it if necessary.
114 @val: the string to append onto the end of the #GString.
115 @Returns: the #GString.
118 <!-- ##### FUNCTION g_string_append_c ##### -->
120 Adds a character onto the end of a #GString, expanding it if necessary.
124 @c: the character to append onto the end of the #GString.
125 @Returns: the #GString.
128 <!-- ##### FUNCTION g_string_append_len ##### -->
130 Appends @len bytes of @val to @string. Because @len is provided,
131 @val may contain embedded nuls and need not be nul-terminated.
135 @val: bytes to append
136 @len: number of bytes of @val to use
137 @Returns: the #GString
140 <!-- ##### FUNCTION g_string_prepend ##### -->
142 Adds a string on to the start of a #GString, expanding it if necessary.
146 @val: the string to prepend on the start of the #GString.
147 @Returns: the #GString.
150 <!-- ##### FUNCTION g_string_prepend_c ##### -->
152 Adds a character onto the start of a #GString, expanding it if necessary.
156 @c: the character to prepend on the start of the #GString.
157 @Returns: the #GString.
160 <!-- ##### FUNCTION g_string_prepend_len ##### -->
162 Prepends @len bytes of @val to @string. Because @len is provided,
163 @val may contain embedded nuls and need not be nul-terminated.
167 @val: bytes to prepend
168 @len: number of bytes in @val to prepend
169 @Returns: the #GString passed in
172 <!-- ##### FUNCTION g_string_insert ##### -->
174 Inserts a copy of a string into a #GString, expanding it if necessary.
178 @pos: the position to insert the copy of the string.
179 @val: the string to insert.
180 @Returns: the #GString.
183 <!-- ##### FUNCTION g_string_insert_c ##### -->
185 Inserts a character into a #GString, expanding it if necessary.
189 @pos: the position to insert the character.
190 @c: the character to insert.
191 @Returns: the #GString.
194 <!-- ##### FUNCTION g_string_insert_len ##### -->
196 Inserts @len bytes of @val into @string at @pos. Because @len is provided, @val
197 may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
201 @pos: position in @string where insertion should happen, or -1 for at the end
202 @val: bytes to insert
203 @len: number of bytes of @val to insert
204 @Returns: the #GString
207 <!-- ##### FUNCTION g_string_erase ##### -->
209 Removes @len characters from a #GString, starting at position @pos.
210 The rest of the #GString is shifted down to fill the gap.
214 @pos: the position of the characters to remove.
215 @len: the number of characters to remove.
216 @Returns: the #GString.
219 <!-- ##### FUNCTION g_string_truncate ##### -->
221 Cuts off the end of the GString, leaving the first @len characters.
225 @len: the new size of the #GString.
226 @Returns: the #GString.
229 <!-- ##### FUNCTION g_string_free ##### -->
231 Frees the memory allocated for the #GString.
232 If free_segment is TRUE it also frees the character data.
236 @free_segment: if TRUE the actual character data is freed as well.
240 <!-- ##### FUNCTION g_string_up ##### -->
242 Converts a #GString to upper case.
246 @Returns: the #GString.
249 <!-- ##### FUNCTION g_string_down ##### -->
251 Converts a #GString to lower case.
255 @Returns: the #GString.
258 <!-- ##### FUNCTION g_string_hash ##### -->
260 Creates a hash code for @str; for use with #GHashTable.
263 @str: a string to hash
264 @Returns: hash code for @str
267 <!-- ##### FUNCTION g_string_equal ##### -->
269 Compares two strings for equality, returning %TRUE if they are equal.
270 For use with #GHashTable.
274 @v2: another #GString
275 @Returns: %TRUE if they strings are the same length and contain the same bytes