Additions
[platform/upstream/glib.git] / docs / reference / glib / tmpl / strings.sgml
1 <!-- ##### SECTION Title ##### -->
2 Strings
3
4 <!-- ##### SECTION Short_Description ##### -->
5 text buffers which grow automatically as text is added.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
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.
12 </para>
13
14 <!-- ##### SECTION See_Also ##### -->
15 <para>
16
17 </para>
18
19 <!-- ##### SECTION Stability_Level ##### -->
20
21
22 <!-- ##### STRUCT GString ##### -->
23 <para>
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 character.
29 </para>
30 <para>
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
33 string.
34 </para>
35
36 @str: 
37 @len: 
38 @allocated_len: 
39
40 <!-- ##### FUNCTION g_string_new ##### -->
41 <para>
42 Creates a new #GString, initialized with the given string.
43 </para>
44
45 @init: the initial text to copy into the string.
46 @Returns: the new #GString.
47
48
49 <!-- ##### FUNCTION g_string_new_len ##### -->
50 <para>
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.
53 </para>
54
55 @init: initial contents of string.
56 @len: length of @init to use.
57 @Returns: a new #GString.
58
59
60 <!-- ##### FUNCTION g_string_sized_new ##### -->
61 <para>
62 Creates a new #GString, with enough space for @dfl_size characters.
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.
65 </para>
66
67 @dfl_size: the default size of the space allocated to hold the string.
68 @Returns: the new #GString.
69
70
71 <!-- ##### FUNCTION g_string_assign ##### -->
72 <para>
73 Copies the characters 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.
76 </para>
77
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.
83
84
85 <!-- ##### MACRO g_string_sprintf ##### -->
86 <para>
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. 
91 </para>
92
93 @Deprecated: This function has been renamed to g_string_printf().
94 <!-- # Unused Parameters # -->
95 @string: a #GString.
96 @format: the string format. See the sprintf() documentation.
97 @Varargs: the parameters to insert into the format string.
98
99
100 <!-- ##### MACRO g_string_sprintfa ##### -->
101 <para>
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. 
105 </para>
106
107 @Deprecated: This function has been renamed to g_string_append_printf().
108 <!-- # Unused Parameters # -->
109 @string: a #GString.
110 @format: the string format. See the sprintf() documentation.
111 @Varargs: the parameters to insert into the format string.
112
113
114 <!-- ##### FUNCTION g_string_printf ##### -->
115 <para>
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.
120 </para>
121
122 @string: a #GString.
123 @format: the string format. See the printf() documentation.
124 @Varargs: the parameters to insert into the format string.
125
126
127 <!-- ##### FUNCTION g_string_append_printf ##### -->
128 <para>
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.
132 </para>
133
134 @string: a #GString.
135 @format: the string format. See the printf() documentation.
136 @Varargs: the parameters to insert into the format string.
137
138
139 <!-- ##### FUNCTION g_string_append ##### -->
140 <para>
141 Adds a string onto the end of a #GString, expanding it if necessary.
142 </para>
143
144 @string: a #GString.
145 @val: the string to append onto the end of the #GString.
146 @Returns: the #GString.
147
148
149 <!-- ##### FUNCTION g_string_append_c ##### -->
150 <para>
151 Adds a character onto the end of a #GString, expanding it if necessary.
152 </para>
153
154 @string: a #GString.
155 @c: the character to append onto the end of the #GString.
156 @Returns: the #GString.
157
158
159 <!-- ##### FUNCTION g_string_append_unichar ##### -->
160 <para>
161
162 </para>
163
164 @string: 
165 @wc: 
166 @Returns: 
167
168
169 <!-- ##### FUNCTION g_string_append_len ##### -->
170 <para>
171 Appends @len bytes of @val to @string. Because @len is provided, 
172 @val may contain embedded nuls and need not be nul-terminated.
173 </para>
174
175 @string: a #GString.
176 @val: bytes to append.
177 @len: number of bytes of @val to use.
178 @Returns: the #GString.
179
180
181 <!-- ##### FUNCTION g_string_prepend ##### -->
182 <para>
183 Adds a string on to the start of a #GString, expanding it if necessary.
184 </para>
185
186 @string: a #GString.
187 @val: the string to prepend on the start of the #GString.
188 @Returns: the #GString.
189
190
191 <!-- ##### FUNCTION g_string_prepend_c ##### -->
192 <para>
193 Adds a character onto the start of a #GString, expanding it if necessary.
194 </para>
195
196 @string: a #GString.
197 @c: the character to prepend on the start of the #GString.
198 @Returns: the #GString.
199
200
201 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
202 <para>
203
204 </para>
205
206 @string: 
207 @wc: 
208 @Returns: 
209
210
211 <!-- ##### FUNCTION g_string_prepend_len ##### -->
212 <para>
213 Prepends @len bytes of @val to @string. Because @len is provided, 
214 @val may contain embedded nuls and need not be nul-terminated.
215 </para>
216
217 @string: a #GString.
218 @val: bytes to prepend.
219 @len: number of bytes in @val to prepend.
220 @Returns: the #GString passed in.
221
222
223 <!-- ##### FUNCTION g_string_insert ##### -->
224 <para>
225 Inserts a copy of a string into a #GString, expanding it if necessary.
226 </para>
227
228 @string: a #GString.
229 @pos: the position to insert the copy of the string.
230 @val: the string to insert.
231 @Returns: the #GString.
232
233
234 <!-- ##### FUNCTION g_string_insert_c ##### -->
235 <para>
236 Inserts a character into a #GString, expanding it if necessary.
237 </para>
238
239 @string: a #GString.
240 @pos: the position to insert the character.
241 @c: the character to insert.
242 @Returns: the #GString.
243
244
245 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
246 <para>
247
248 </para>
249
250 @string: 
251 @pos: 
252 @wc: 
253 @Returns: 
254
255
256 <!-- ##### FUNCTION g_string_insert_len ##### -->
257 <para>
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.
260 </para>
261
262 @string: a #GString.
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.
267
268
269 <!-- ##### FUNCTION g_string_erase ##### -->
270 <para>
271 Removes @len characters from a #GString, starting at position @pos.
272 The rest of the #GString is shifted down to fill the gap.
273 </para>
274
275 @string: a #GString.
276 @pos: the position of the characters to remove.
277 @len: the number of characters to remove, or -1 to remove all
278       following characters.
279 @Returns: the #GString.
280
281
282 <!-- ##### FUNCTION g_string_truncate ##### -->
283 <para>
284 Cuts off the end of the GString, leaving the first @len characters.
285 </para>
286
287 @string: a #GString.
288 @len: the new size of the #GString.
289 @Returns: the #GString.
290
291
292 <!-- ##### FUNCTION g_string_set_size ##### -->
293 <para>
294
295 </para>
296
297 @string: 
298 @len: 
299 @Returns: 
300
301
302 <!-- ##### FUNCTION g_string_free ##### -->
303 <para>
304 Frees the memory allocated for the #GString.
305 If @free_segment is %TRUE it also frees the character data.
306 </para>
307
308 @string: a #GString.
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)
311
312
313 <!-- ##### FUNCTION g_string_up ##### -->
314 <para>
315 </para>
316
317 @string: 
318 @Returns: 
319
320
321 <!-- ##### FUNCTION g_string_down ##### -->
322 <para>
323 </para>
324
325 @string: 
326 @Returns: 
327
328
329 <!-- ##### FUNCTION g_string_hash ##### -->
330 <para>
331 Creates a hash code for @str; for use with #GHashTable.
332 </para>
333
334 @str: a string to hash.
335 @Returns: hash code for @str.
336
337
338 <!-- ##### FUNCTION g_string_equal ##### -->
339 <para>
340 Compares two strings for equality, returning %TRUE if they are equal. 
341 For use with #GHashTable.
342 </para>
343
344 @v: a #GString.
345 @v2: another #GString.
346 @Returns: %TRUE if they strings are the same length and contain the same bytes.
347
348