add glibintl.h
[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
36 <!-- ##### FUNCTION g_string_new ##### -->
37 <para>
38 Creates a new #GString, initialized with the given string.
39 </para>
40
41 @init: the initial text to copy into the string.
42 @Returns: the new #GString.
43
44
45 <!-- ##### FUNCTION g_string_new_len ##### -->
46 <para>
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.
49 </para>
50
51 @init: initial contents of string
52 @len: length of @init to use
53 @Returns: a new #GString
54
55
56 <!-- ##### FUNCTION g_string_sized_new ##### -->
57 <para>
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.
61 </para>
62
63 @dfl_size: the default size of the space allocated to hold the string.
64 @Returns: the new #GString.
65
66
67 <!-- ##### FUNCTION g_string_assign ##### -->
68 <para>
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.
72 </para>
73
74 @string: the destination #GString. Its current contents are destroyed.
75 @rval: the source #GString.
76 @Returns: the destination #GString.
77
78
79 <!-- ##### MACRO g_string_sprintf ##### -->
80 <para>
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.
85 </para>
86
87 <!-- # Unused Parameters # -->
88 @string: a #GString.
89 @format: the string format. See the <function>sprintf()</function>
90 documentation.
91 @Varargs: the parameters to insert into the format string.
92
93
94 <!-- ##### MACRO g_string_sprintfa ##### -->
95 <para>
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.
99 </para>
100
101 <!-- # Unused Parameters # -->
102 @string: a #GString.
103 @format: the string format. See the <function>sprintf()</function>
104 documentation.
105 @Varargs: the parameters to insert into the format string.
106
107
108 <!-- ##### FUNCTION g_string_printf ##### -->
109 <para>
110
111 </para>
112
113 @string: 
114 @format: 
115 @Varargs: 
116
117
118 <!-- ##### FUNCTION g_string_printfa ##### -->
119 <para>
120
121 </para>
122
123 @string: 
124 @format: 
125 @Varargs: 
126
127
128 <!-- ##### FUNCTION g_string_append ##### -->
129 <para>
130 Adds a string onto the end of a #GString, expanding it if necessary.
131 </para>
132
133 @string: a #GString.
134 @val: the string to append onto the end of the #GString.
135 @Returns: the #GString.
136
137
138 <!-- ##### FUNCTION g_string_append_c ##### -->
139 <para>
140 Adds a character onto the end of a #GString, expanding it if necessary.
141 </para>
142
143 @string: a #GString.
144 @c: the character to append onto the end of the #GString.
145 @Returns: the #GString.
146
147
148 <!-- ##### FUNCTION g_string_append_len ##### -->
149 <para>
150 Appends @len bytes of @val to @string. Because @len is provided, 
151 @val may contain embedded nuls and need not be nul-terminated.
152 </para>
153
154 @string: a #GString
155 @val: bytes to append
156 @len: number of bytes of @val to use
157 @Returns: the #GString
158
159
160 <!-- ##### FUNCTION g_string_prepend ##### -->
161 <para>
162 Adds a string on to the start of a #GString, expanding it if necessary.
163 </para>
164
165 @string: a #GString.
166 @val: the string to prepend on the start of the #GString.
167 @Returns: the #GString.
168
169
170 <!-- ##### FUNCTION g_string_prepend_c ##### -->
171 <para>
172 Adds a character onto the start of a #GString, expanding it if necessary.
173 </para>
174
175 @string: a #GString.
176 @c: the character to prepend on the start of the #GString.
177 @Returns: the #GString.
178
179
180 <!-- ##### FUNCTION g_string_prepend_len ##### -->
181 <para>
182 Prepends @len bytes of @val to @string. Because @len is provided, 
183 @val may contain embedded nuls and need not be nul-terminated.
184 </para>
185
186 @string: a #GString
187 @val: bytes to prepend
188 @len: number of bytes in @val to prepend
189 @Returns: the #GString passed in
190
191
192 <!-- ##### FUNCTION g_string_insert ##### -->
193 <para>
194 Inserts a copy of a string into a #GString, expanding it if necessary.
195 </para>
196
197 @string: a #GString.
198 @pos: the position to insert the copy of the string.
199 @val: the string to insert.
200 @Returns: the #GString.
201
202
203 <!-- ##### FUNCTION g_string_insert_c ##### -->
204 <para>
205 Inserts a character into a #GString, expanding it if necessary.
206 </para>
207
208 @string: a #GString.
209 @pos: the position to insert the character.
210 @c: the character to insert.
211 @Returns: the #GString.
212
213
214 <!-- ##### FUNCTION g_string_insert_len ##### -->
215 <para>
216 Inserts @len bytes of @val into @string at @pos.  Because @len is provided, @val
217  may contain embedded nuls and need not be nul-terminated. If @pos is -1, bytes are inserted at the end of the string.
218 </para>
219
220 @string: a #GString
221 @pos: position in @string where insertion should happen, or -1 for at the end
222 @val: bytes to insert
223 @len: number of bytes of @val to insert
224 @Returns: the #GString
225
226
227 <!-- ##### FUNCTION g_string_erase ##### -->
228 <para>
229 Removes @len characters from a #GString, starting at position @pos.
230 The rest of the #GString is shifted down to fill the gap.
231 </para>
232
233 @string: a #GString.
234 @pos: the position of the characters to remove.
235 @len: the number of characters to remove.
236 @Returns: the #GString.
237
238
239 <!-- ##### FUNCTION g_string_truncate ##### -->
240 <para>
241 Cuts off the end of the GString, leaving the first @len characters.
242 </para>
243
244 @string: a #GString.
245 @len: the new size of the #GString.
246 @Returns: the #GString.
247
248
249 <!-- ##### FUNCTION g_string_free ##### -->
250 <para>
251 Frees the memory allocated for the #GString.
252 If free_segment is TRUE it also frees the character data.
253 </para>
254
255 @string: a #GString.
256 @free_segment: if TRUE the actual character data is freed as well.
257 @Returns: 
258
259
260 <!-- ##### FUNCTION g_string_up ##### -->
261 <para>
262 Converts a #GString to upper case.
263 </para>
264
265 @string: a #GString.
266 @Returns: the #GString.
267
268
269 <!-- ##### FUNCTION g_string_down ##### -->
270 <para>
271 Converts a #GString to lower case.
272 </para>
273
274 @string: a #GString.
275 @Returns: the #GString.
276
277
278 <!-- ##### FUNCTION g_string_hash ##### -->
279 <para>
280 Creates a hash code for @str; for use with #GHashTable.
281 </para>
282
283 @str: a string to hash
284 @Returns: hash code for @str
285
286
287 <!-- ##### FUNCTION g_string_equal ##### -->
288 <para>
289 Compares two strings for equality, returning %TRUE if they are equal. 
290 For use with #GHashTable.
291 </para>
292
293 @v: a #GString
294 @v2: another #GString
295 @Returns: %TRUE if they strings are the same length and contain the same bytes
296
297