Update.
[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 null character.
26 </para>
27 <para>
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
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 strcpy() 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
112 </para>
113
114 @string: 
115 @format: 
116 @Varargs: 
117
118
119 <!-- ##### FUNCTION g_string_printfa ##### -->
120 <para>
121
122 </para>
123
124 @string: 
125 @format: 
126 @Varargs: 
127
128
129 <!-- ##### FUNCTION g_string_append ##### -->
130 <para>
131 Adds a string onto the end of a #GString, expanding it if necessary.
132 </para>
133
134 @string: a #GString.
135 @val: the string to append onto the end of the #GString.
136 @Returns: the #GString.
137
138
139 <!-- ##### FUNCTION g_string_append_c ##### -->
140 <para>
141 Adds a character onto the end of a #GString, expanding it if necessary.
142 </para>
143
144 @string: a #GString.
145 @c: the character to append onto the end of the #GString.
146 @Returns: the #GString.
147
148
149 <!-- ##### FUNCTION g_string_append_unichar ##### -->
150 <para>
151
152 </para>
153
154 @string: 
155 @wc: 
156 @Returns: 
157
158
159 <!-- ##### FUNCTION g_string_append_len ##### -->
160 <para>
161 Appends @len bytes of @val to @string. Because @len is provided, 
162 @val may contain embedded nuls and need not be nul-terminated.
163 </para>
164
165 @string: a #GString
166 @val: bytes to append
167 @len: number of bytes of @val to use
168 @Returns: the #GString
169
170
171 <!-- ##### FUNCTION g_string_prepend ##### -->
172 <para>
173 Adds a string on to the start of a #GString, expanding it if necessary.
174 </para>
175
176 @string: a #GString.
177 @val: the string to prepend on the start of the #GString.
178 @Returns: the #GString.
179
180
181 <!-- ##### FUNCTION g_string_prepend_c ##### -->
182 <para>
183 Adds a character onto the start of a #GString, expanding it if necessary.
184 </para>
185
186 @string: a #GString.
187 @c: the character to prepend on the start of the #GString.
188 @Returns: the #GString.
189
190
191 <!-- ##### FUNCTION g_string_prepend_unichar ##### -->
192 <para>
193
194 </para>
195
196 @string: 
197 @wc: 
198 @Returns: 
199
200
201 <!-- ##### FUNCTION g_string_prepend_len ##### -->
202 <para>
203 Prepends @len bytes of @val to @string. Because @len is provided, 
204 @val may contain embedded nuls and need not be nul-terminated.
205 </para>
206
207 @string: a #GString
208 @val: bytes to prepend
209 @len: number of bytes in @val to prepend
210 @Returns: the #GString passed in
211
212
213 <!-- ##### FUNCTION g_string_insert ##### -->
214 <para>
215 Inserts a copy of a string into a #GString, expanding it if necessary.
216 </para>
217
218 @string: a #GString.
219 @pos: the position to insert the copy of the string.
220 @val: the string to insert.
221 @Returns: the #GString.
222
223
224 <!-- ##### FUNCTION g_string_insert_c ##### -->
225 <para>
226 Inserts a character into a #GString, expanding it if necessary.
227 </para>
228
229 @string: a #GString.
230 @pos: the position to insert the character.
231 @c: the character to insert.
232 @Returns: the #GString.
233
234
235 <!-- ##### FUNCTION g_string_insert_unichar ##### -->
236 <para>
237
238 </para>
239
240 @string: 
241 @pos: 
242 @wc: 
243 @Returns: 
244
245
246 <!-- ##### FUNCTION g_string_insert_len ##### -->
247 <para>
248 Inserts @len bytes of @val into @string at @pos.  Because @len is provided, @val
249  may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
250 </para>
251
252 @string: a #GString
253 @pos: position in @string where insertion should happen, or -1 for at the end
254 @val: bytes to insert
255 @len: number of bytes of @val to insert
256 @Returns: the #GString
257
258
259 <!-- ##### FUNCTION g_string_erase ##### -->
260 <para>
261 Removes @len characters from a #GString, starting at position @pos.
262 The rest of the #GString is shifted down to fill the gap.
263 </para>
264
265 @string: a #GString.
266 @pos: the position of the characters to remove.
267 @len: the number of characters to remove, or -1 to remove all
268       following characters.
269 @Returns: the #GString.
270
271
272 <!-- ##### FUNCTION g_string_truncate ##### -->
273 <para>
274 Cuts off the end of the GString, leaving the first @len characters.
275 </para>
276
277 @string: a #GString.
278 @len: the new size of the #GString.
279 @Returns: the #GString.
280
281
282 <!-- ##### FUNCTION g_string_set_size ##### -->
283 <para>
284
285 </para>
286
287 @string: 
288 @len: 
289 @Returns: 
290
291
292 <!-- ##### FUNCTION g_string_free ##### -->
293 <para>
294 Frees the memory allocated for the #GString.
295 If free_segment is TRUE it also frees the character data.
296 </para>
297
298 @string: a #GString.
299 @free_segment: if TRUE the actual character data is freed as well.
300 @Returns: 
301
302
303 <!-- ##### FUNCTION g_string_up ##### -->
304 <para>
305 Converts a #GString to upper case.
306 </para>
307
308 @string: a #GString.
309 @Returns: the #GString.
310
311
312 <!-- ##### FUNCTION g_string_down ##### -->
313 <para>
314 Converts a #GString to lower case.
315 </para>
316
317 @string: a #GString.
318 @Returns: the #GString.
319
320
321 <!-- ##### FUNCTION g_string_hash ##### -->
322 <para>
323 Creates a hash code for @str; for use with #GHashTable.
324 </para>
325
326 @str: a string to hash
327 @Returns: hash code for @str
328
329
330 <!-- ##### FUNCTION g_string_equal ##### -->
331 <para>
332 Compares two strings for equality, returning %TRUE if they are equal. 
333 For use with #GHashTable.
334 </para>
335
336 @v: a #GString
337 @v2: another #GString
338 @Returns: %TRUE if they strings are the same length and contain the same bytes
339
340