Added
[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
10 automatically as text is appended or inserted.
11 </para>
12 <para>
13 The space allocated for the string is always a power of two, so as the
14 string grows it will occupy 2, 4, 8, 16, 32, 64, 128 etc. characters.
15 </para>
16
17 <!-- ##### SECTION See_Also ##### -->
18 <para>
19
20 </para>
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 null character.
29 </para>
30 <para>
31 The str field is zero-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
39 <!-- ##### FUNCTION g_string_new ##### -->
40 <para>
41 Creates a new #GString, initialized with the given string.
42 </para>
43
44 @init: the initial text to copy into the string.
45 @Returns: the new #GString.
46
47
48 <!-- ##### FUNCTION g_string_new_len ##### -->
49 <para>
50
51 </para>
52
53 @init: 
54 @len: 
55 @Returns: 
56
57
58 <!-- ##### FUNCTION g_string_sized_new ##### -->
59 <para>
60 Creates a new GString, with enough space for @dfl_size characters.
61 This is useful if you are going to add a lot of text to the string and
62 don't want it to be reallocated too often.
63 </para>
64
65 @dfl_size: the default size of the space allocated to hold the string.
66 @Returns: the new #GString.
67
68
69 <!-- ##### FUNCTION g_string_assign ##### -->
70 <para>
71 Copies the characters from one #GString into another, destroying any previous
72 contents. It is rather like the standard strcpy() function, except that
73 you do not have to worry about having enough space to copy the string.
74 </para>
75
76 @string: the destination #GString. Its current contents are destroyed.
77 @rval: the source #GString.
78 @Returns: the destination #GString.
79
80
81 <!-- ##### FUNCTION g_string_sprintf ##### -->
82 <para>
83 Writes a formatted string into a #GString.
84 This is similar to the standard <function>sprintf()</function> function,
85 except that the GString buffer automatically expands to contain the results.
86 The previous contents of the GString are destroyed.
87 </para>
88
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 <!-- ##### FUNCTION 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 @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_append ##### -->
109 <para>
110 Adds a string onto the end of a #GString, expanding it if necessary.
111 </para>
112
113 @string: a #GString.
114 @val: the string to append onto the end of the #GString.
115 @Returns: the #GString.
116
117
118 <!-- ##### FUNCTION g_string_append_c ##### -->
119 <para>
120 Adds a character onto the end of a #GString, expanding it if necessary.
121 </para>
122
123 @string: a #GString.
124 @c: the character to append onto the end of the #GString.
125 @Returns: the #GString.
126
127
128 <!-- ##### FUNCTION g_string_append_len ##### -->
129 <para>
130
131 </para>
132
133 @string: 
134 @val: 
135 @len: 
136 @Returns: 
137
138
139 <!-- ##### FUNCTION g_string_prepend ##### -->
140 <para>
141 Adds a string on to the start of a #GString, expanding it if necessary.
142 </para>
143
144 @string: a #GString.
145 @val: the string to prepend on the start of the #GString.
146 @Returns: the #GString.
147
148
149 <!-- ##### FUNCTION g_string_prepend_c ##### -->
150 <para>
151 Adds a character onto the start of a #GString, expanding it if necessary.
152 </para>
153
154 @string: a #GString.
155 @c: the character to prepend on the start of the #GString.
156 @Returns: the #GString.
157
158
159 <!-- ##### FUNCTION g_string_prepend_len ##### -->
160 <para>
161
162 </para>
163
164 @string: 
165 @val: 
166 @len: 
167 @Returns: 
168
169
170 <!-- ##### FUNCTION g_string_insert ##### -->
171 <para>
172 Inserts a copy of a string into a #GString, expanding it if necessary.
173 </para>
174
175 @string: a #GString.
176 @pos: the position to insert the copy of the string.
177 @val: the string to insert.
178 @Returns: the #GString.
179
180
181 <!-- ##### FUNCTION g_string_insert_c ##### -->
182 <para>
183 Inserts a character into a #GString, expanding it if necessary.
184 </para>
185
186 @string: a #GString.
187 @pos: the position to insert the character.
188 @c: the character to insert.
189 @Returns: the #GString.
190
191
192 <!-- ##### FUNCTION g_string_insert_len ##### -->
193 <para>
194
195 </para>
196
197 @string: 
198 @pos: 
199 @val: 
200 @len: 
201 @Returns: 
202
203
204 <!-- ##### FUNCTION g_string_erase ##### -->
205 <para>
206 Removes @len characters from a #GString, starting at position @pos.
207 The rest of the #GString is shifted down to fill the gap.
208 </para>
209
210 @string: a #GString.
211 @pos: the position of the characters to remove.
212 @len: the number of characters to remove.
213 @Returns: the #GString.
214
215
216 <!-- ##### FUNCTION g_string_truncate ##### -->
217 <para>
218 Cuts off the end of the GString, leaving the first @len characters.
219 </para>
220
221 @string: a #GString.
222 @len: the new size of the #GString.
223 @Returns: the #GString.
224
225
226 <!-- ##### FUNCTION g_string_free ##### -->
227 <para>
228 Frees the memory allocated for the #GString.
229 If free_segment is TRUE it also frees the character data.
230 </para>
231
232 @string: a #GString.
233 @free_segment: if TRUE the actual character data is freed as well.
234 @Returns: 
235
236
237 <!-- ##### FUNCTION g_string_up ##### -->
238 <para>
239 Converts a #GString to upper case.
240 </para>
241
242 @string: a #GString.
243 @Returns: the #GString.
244
245
246 <!-- ##### FUNCTION g_string_down ##### -->
247 <para>
248 Converts a #GString to lower case.
249 </para>
250
251 @string: a #GString.
252 @Returns: the #GString.
253
254
255 <!-- ##### FUNCTION g_string_hash ##### -->
256 <para>
257
258 </para>
259
260 @str: 
261 @Returns: 
262
263
264 <!-- ##### FUNCTION g_string_equal ##### -->
265 <para>
266
267 </para>
268
269 @v: 
270 @v2: 
271 @Returns: 
272
273