0949983b96b7f594e46ba49034b992e9d1b826f7
[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_sized_new ##### -->
49 <para>
50 Creates a new GString, with enough space for @dfl_size characters.
51 This is useful if you are going to add a lot of text to the string and
52 don't want it to be reallocated too often.
53 </para>
54
55 @dfl_size: the default size of the space allocated to hold the string.
56 @Returns: the new #GString.
57
58
59 <!-- ##### FUNCTION g_string_assign ##### -->
60 <para>
61 Copies the characters from one #GString into another, destroying any previous
62 contents. It is rather like the standard strcpy() function, except that
63 you do not have to worry about having enough space to copy the string.
64 </para>
65
66 @string: 
67 @rval: the source #GString.
68 @Returns: the destination #GString.
69 <!-- # Unused Parameters # -->
70 @lval: the destination #GString. Its current contents are destroyed.
71
72
73 <!-- ##### FUNCTION g_string_sprintf ##### -->
74 <para>
75 Writes a formatted string into a #GString.
76 This is similar to the standard <function>sprintf()</function> function,
77 except that the GString buffer automatically expands to contain the results.
78 The previous contents of the GString are destroyed.
79 </para>
80
81 @string: a #GString.
82 @format: the string format. See the <function>sprintf()</function>
83 documentation.
84 @Varargs: the parameters to insert into the format string.
85
86
87 <!-- ##### FUNCTION g_string_sprintfa ##### -->
88 <para>
89 Appends a formatted string onto the end of a #GString.
90 This function is is similar to g_string_sprintf() except that
91 the text is appended to the GString.
92 </para>
93
94 @string: a #GString.
95 @format: the string format. See the <function>sprintf()</function>
96 documentation.
97 @Varargs: the parameters to insert into the format string.
98
99
100 <!-- ##### FUNCTION g_string_append ##### -->
101 <para>
102 Adds a string onto the end of a #GString, expanding it if necessary.
103 </para>
104
105 @string: a #GString.
106 @val: the string to append onto the end of the #GString.
107 @Returns: the #GString.
108
109
110 <!-- ##### FUNCTION g_string_append_c ##### -->
111 <para>
112 Adds a character onto the end of a #GString, expanding it if necessary.
113 </para>
114
115 @string: a #GString.
116 @c: the character to append onto the end of the #GString.
117 @Returns: the #GString.
118
119
120 <!-- ##### FUNCTION g_string_append_len ##### -->
121 <para>
122
123 </para>
124
125 @string: 
126 @val: 
127 @len: 
128 @Returns: 
129
130
131 <!-- ##### FUNCTION g_string_prepend ##### -->
132 <para>
133 Adds a string on to the start of a #GString, expanding it if necessary.
134 </para>
135
136 @string: a #GString.
137 @val: the string to prepend on the start of the #GString.
138 @Returns: the #GString.
139
140
141 <!-- ##### FUNCTION g_string_prepend_c ##### -->
142 <para>
143 Adds a character onto the start of a #GString, expanding it if necessary.
144 </para>
145
146 @string: a #GString.
147 @c: the character to prepend on the start of the #GString.
148 @Returns: the #GString.
149
150
151 <!-- ##### FUNCTION g_string_prepend_len ##### -->
152 <para>
153
154 </para>
155
156 @string: 
157 @val: 
158 @len: 
159 @Returns: 
160
161
162 <!-- ##### FUNCTION g_string_insert ##### -->
163 <para>
164 Inserts a copy of a string into a #GString, expanding it if necessary.
165 </para>
166
167 @string: a #GString.
168 @pos: the position to insert the copy of the string.
169 @val: the string to insert.
170 @Returns: the #GString.
171
172
173 <!-- ##### FUNCTION g_string_insert_c ##### -->
174 <para>
175 Inserts a character into a #GString, expanding it if necessary.
176 </para>
177
178 @string: a #GString.
179 @pos: the position to insert the character.
180 @c: the character to insert.
181 @Returns: the #GString.
182
183
184 <!-- ##### FUNCTION g_string_insert_len ##### -->
185 <para>
186
187 </para>
188
189 @string: 
190 @pos: 
191 @val: 
192 @len: 
193 @Returns: 
194
195
196 <!-- ##### FUNCTION g_string_erase ##### -->
197 <para>
198 Removes @len characters from a #GString, starting at position @pos.
199 The rest of the #GString is shifted down to fill the gap.
200 </para>
201
202 @string: a #GString.
203 @pos: the position of the characters to remove.
204 @len: the number of characters to remove.
205 @Returns: the #GString.
206
207
208 <!-- ##### FUNCTION g_string_truncate ##### -->
209 <para>
210 Cuts off the end of the GString, leaving the first @len characters.
211 </para>
212
213 @string: a #GString.
214 @len: the new size of the #GString.
215 @Returns: the #GString.
216
217
218 <!-- ##### FUNCTION g_string_free ##### -->
219 <para>
220 Frees the memory allocated for the #GString.
221 If free_segment is TRUE it also frees the character data.
222 </para>
223
224 @string: a #GString.
225 @free_segment: if TRUE the actual character data is freed as well.
226 @Returns: 
227
228
229 <!-- ##### FUNCTION g_string_up ##### -->
230 <para>
231 Converts a #GString to upper case.
232 </para>
233
234 @string: a #GString.
235 @Returns: the #GString.
236
237
238 <!-- ##### FUNCTION g_string_down ##### -->
239 <para>
240 Converts a #GString to lower case.
241 </para>
242
243 @string: a #GString.
244 @Returns: the #GString.
245
246
247 <!-- ##### FUNCTION g_string_hash ##### -->
248 <para>
249
250 </para>
251
252 @str: 
253 @Returns: 
254
255
256 <!-- ##### FUNCTION g_string_equal ##### -->
257 <para>
258
259 </para>
260
261 @v: 
262 @v2: 
263 @Returns: 
264
265