58cf10cc1931d26df2d9fa3c0e80b1904be36f66
[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 <!-- ##### STRUCT GString ##### -->
20 <para>
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 nul character.
26 </para>
27 <para>
28 The <structfield>str</structfield> field is nul-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
30 string.
31 </para>
32
33 @str: 
34 @len: 
35 @allocated_len: 
36
37 <!-- ##### FUNCTION g_string_new ##### -->
38 <para>
39 Creates a new #GString, initialized with the given string.
40 </para>
41
42 @init: the initial text to copy into the string.
43 @Returns: the new #GString.
44
45
46 <!-- ##### FUNCTION g_string_new_len ##### -->
47 <para>
48 Creates a new #GString with @len bytes of the @init buffer.  Because a length is
49 provided, @init need not be nul-terminated, and can contain embedded nul bytes.
50 </para>
51
52 @init: initial contents of string.
53 @len: length of @init to use.
54 @Returns: a new #GString.
55
56
57 <!-- ##### FUNCTION g_string_sized_new ##### -->
58 <para>
59 Creates a new #GString, with enough space for @dfl_size characters.
60 This is useful if you are going to add a lot of text to the string and
61 don't want it to be reallocated too often.
62 </para>
63
64 @dfl_size: the default size of the space allocated to hold the string.
65 @Returns: the new #GString.
66
67
68 <!-- ##### FUNCTION g_string_assign ##### -->
69 <para>
70 Copies the characters from one #GString into another, destroying any previous
71 contents. It is rather like the standard <function>strcpy()</function> function, except that
72 you do not have to worry about having enough space to copy the string.
73 </para>
74
75 @string: the destination #GString. Its current contents are destroyed.
76 @rval: the source #GString.
77 @Returns: the destination #GString.
78
79
80 <!-- ##### MACRO g_string_sprintf ##### -->
81 <para>
82 Writes a formatted string into a #GString.
83 This is similar to the standard <function>sprintf()</function> function,
84 except that the #GString buffer automatically expands to contain the results.
85 The previous contents of the #GString are destroyed.
86 </para>
87
88 <!-- # Unused Parameters # -->
89 @string: a #GString.
90 @format: the string format. See the <function>sprintf()</function>
91 documentation.
92 @Varargs: the parameters to insert into the format string.
93
94
95 <!-- ##### MACRO g_string_sprintfa ##### -->
96 <para>
97 Appends a formatted string onto the end of a #GString.
98 This function is is similar to g_string_sprintf() except that
99 the text is appended to the #GString.
100 </para>
101
102 <!-- # Unused Parameters # -->
103 @string: a #GString.
104 @format: the string format. See the <function>sprintf()</function>
105 documentation.
106 @Varargs: the parameters to insert into the format string.
107
108
109 <!-- ##### FUNCTION g_string_printf ##### -->
110 <para>
111 Writes a formatted string into a #GString.
112 This is similar to the standard <function>sprintf()</function> function,
113 except that the #GString buffer automatically expands to contain the results.
114 The previous contents of the #GString are destroyed.
115 </para>
116
117 @string: a #GString.
118 @format: the string format. See the <function>sprintf()</function>
119 documentation.
120 @Varargs: the parameters to insert into the format string.
121
122
123 <!-- ##### FUNCTION g_string_printfa ##### -->
124 <para>
125 Appends a formatted string onto the end of a #GString.
126 This function is is similar to g_string_sprintf() except that
127 the text is appended to the #GString.
128 </para>
129
130 @string: a #GString.
131 @format: the string format. See the <function>sprintf()</function>
132 documentation.
133 @Varargs: the parameters to insert into the format string.
134
135
136 <!-- ##### FUNCTION g_string_append ##### -->
137 <para>
138 Adds a string onto the end of a #GString, expanding it if necessary.
139 </para>
140
141 @string: a #GString.
142 @val: the string to append onto the end of the #GString.
143 @Returns: the #GString.
144
145
146 <!-- ##### FUNCTION g_string_append_c ##### -->
147 <para>
148 Adds a character onto the end of a #GString, expanding it if necessary.
149 </para>
150
151 @string: a #GString.
152 @c: the character to append onto the end of the #GString.
153 @Returns: the #GString.
154
155
156 <!-- ##### FUNCTION g_string_append_unichar ##### -->
157 <para>
158
159 </para>
160
161 @string: 
162 @wc: 
163 @Returns: 
164
165
166 <!-- ##### FUNCTION g_string_append_len ##### -->
167 <para>
168 Appends @len bytes of @val to @string. Because @len is provided, 
169 @val may contain embedded nuls and need not be nul-terminated.
170 </para>
171
172 @string: a #GString.
173 @val: bytes to append.
174 @len: number of bytes of @val to use.
175 @Returns: the #GString.
176
177
178 <!-- ##### FUNCTION g_string_prepend ##### -->
179 <para>
180 Adds a string on to the start of a #GString, expanding it if necessary.
181 </para>
182
183 @string: a #GString.
184 @val: the string to prepend on the start of the #GString.
185 @Returns: the #GString.
186
187
188 <!-- ##### FUNCTION g_string_prepend_c ##### -->
189 <para>
190 Adds a character onto the start of a #GString, expanding it if necessary.
191 </para>
192
193 @string: a #GString.
194 @c: the character to prepend on the start of the #GString.
195 @Returns: the #GString.
196
197
198 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
199 <para>
200
201 </para>
202
203 @string: 
204 @wc: 
205 @Returns: 
206
207
208 <!-- ##### FUNCTION g_string_prepend_len ##### -->
209 <para>
210 Prepends @len bytes of @val to @string. Because @len is provided, 
211 @val may contain embedded nuls and need not be nul-terminated.
212 </para>
213
214 @string: a #GString.
215 @val: bytes to prepend.
216 @len: number of bytes in @val to prepend.
217 @Returns: the #GString passed in.
218
219
220 <!-- ##### FUNCTION g_string_insert ##### -->
221 <para>
222 Inserts a copy of a string into a #GString, expanding it if necessary.
223 </para>
224
225 @string: a #GString.
226 @pos: the position to insert the copy of the string.
227 @val: the string to insert.
228 @Returns: the #GString.
229
230
231 <!-- ##### FUNCTION g_string_insert_c ##### -->
232 <para>
233 Inserts a character into a #GString, expanding it if necessary.
234 </para>
235
236 @string: a #GString.
237 @pos: the position to insert the character.
238 @c: the character to insert.
239 @Returns: the #GString.
240
241
242 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
243 <para>
244
245 </para>
246
247 @string: 
248 @pos: 
249 @wc: 
250 @Returns: 
251
252
253 <!-- ##### FUNCTION g_string_insert_len ##### -->
254 <para>
255 Inserts @len bytes of @val into @string at @pos.  Because @len is provided, @val
256  may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
257 </para>
258
259 @string: a #GString.
260 @pos: position in @string where insertion should happen, or -1 for at the end.
261 @val: bytes to insert.
262 @len: number of bytes of @val to insert.
263 @Returns: the #GString.
264
265
266 <!-- ##### FUNCTION g_string_erase ##### -->
267 <para>
268 Removes @len characters from a #GString, starting at position @pos.
269 The rest of the #GString is shifted down to fill the gap.
270 </para>
271
272 @string: a #GString.
273 @pos: the position of the characters to remove.
274 @len: the number of characters to remove, or -1 to remove all
275       following characters.
276 @Returns: the #GString.
277
278
279 <!-- ##### FUNCTION g_string_truncate ##### -->
280 <para>
281 Cuts off the end of the GString, leaving the first @len characters.
282 </para>
283
284 @string: a #GString.
285 @len: the new size of the #GString.
286 @Returns: the #GString.
287
288
289 <!-- ##### FUNCTION g_string_set_size ##### -->
290 <para>
291
292 </para>
293
294 @string: 
295 @len: 
296 @Returns: 
297
298
299 <!-- ##### FUNCTION g_string_free ##### -->
300 <para>
301 Frees the memory allocated for the #GString.
302 If @free_segment is %TRUE it also frees the character data.
303 </para>
304
305 @string: a #GString.
306 @free_segment: if %TRUE the actual character data is freed as well.
307
308
309 <!-- ##### FUNCTION g_string_up ##### -->
310 <para>
311 Converts a #GString to upper case.
312 </para>
313
314 @string: a #GString.
315 @Returns: the #GString.
316
317
318 <!-- ##### FUNCTION g_string_down ##### -->
319 <para>
320 Converts a #GString to lower case.
321 </para>
322
323 @string: a #GString.
324 @Returns: the #GString.
325
326
327 <!-- ##### FUNCTION g_string_hash ##### -->
328 <para>
329 Creates a hash code for @str; for use with #GHashTable.
330 </para>
331
332 @str: a string to hash.
333 @Returns: hash code for @str.
334
335
336 <!-- ##### FUNCTION g_string_equal ##### -->
337 <para>
338 Compares two strings for equality, returning %TRUE if they are equal. 
339 For use with #GHashTable.
340 </para>
341
342 @v: a #GString.
343 @v2: another #GString.
344 @Returns: %TRUE if they strings are the same length and contain the same bytes.
345
346