Initial revision
[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 @lval: the destination #GString. Its current contents are destroyed.
67 @rval: the source #GString.
68 @Returns: the destination #GString.
69
70
71 <!-- ##### FUNCTION g_string_sprintf ##### -->
72 <para>
73 Writes a formatted string into a #GString.
74 This is similar to the standard <function>sprintf()</function> function,
75 except that the GString buffer automatically expands to contain the results.
76 The previous contents of the GString are destroyed.
77 </para>
78
79 @string: a #GString.
80 @format: the string format. See the <function>sprintf()</function>
81 documentation.
82 @Varargs: the parameters to insert into the format string.
83
84
85 <!-- ##### FUNCTION g_string_sprintfa ##### -->
86 <para>
87 Appends a formatted string onto the end of a #GString.
88 This function is is similar to g_string_sprintf() except that
89 the text is appended to the GString.
90 </para>
91
92 @string: a #GString.
93 @format: the string format. See the <function>sprintf()</function>
94 documentation.
95 @Varargs: the parameters to insert into the format string.
96
97
98 <!-- ##### FUNCTION g_string_append ##### -->
99 <para>
100 Adds a string onto the end of a #GString, expanding it if necessary.
101 </para>
102
103 @string: a #GString.
104 @val: the string to append onto the end of the #GString.
105 @Returns: the #GString.
106
107
108 <!-- ##### FUNCTION g_string_append_c ##### -->
109 <para>
110 Adds a character onto the end of a #GString, expanding it if necessary.
111 </para>
112
113 @string: a #GString.
114 @c: the character to append onto the end of the #GString.
115 @Returns: the #GString.
116
117
118 <!-- ##### FUNCTION g_string_prepend ##### -->
119 <para>
120 Adds a string on to the start of a #GString, expanding it if necessary.
121 </para>
122
123 @string: a #GString.
124 @val: the string to prepend on the start of the #GString.
125 @Returns: the #GString.
126
127
128 <!-- ##### FUNCTION g_string_prepend_c ##### -->
129 <para>
130 Adds a character onto the start of a #GString, expanding it if necessary.
131 </para>
132
133 @string: a #GString.
134 @c: the character to prepend on the start of the #GString.
135 @Returns: the #GString.
136
137
138 <!-- ##### FUNCTION g_string_insert ##### -->
139 <para>
140 Inserts a copy of a string into a #GString, expanding it if necessary.
141 </para>
142
143 @string: a #GString.
144 @pos: the position to insert the copy of the string.
145 @val: the string to insert.
146 @Returns: the #GString.
147
148
149 <!-- ##### FUNCTION g_string_insert_c ##### -->
150 <para>
151 Inserts a character into a #GString, expanding it if necessary.
152 </para>
153
154 @string: a #GString.
155 @pos: the position to insert the character.
156 @c: the character to insert.
157 @Returns: the #GString.
158
159
160 <!-- ##### FUNCTION g_string_erase ##### -->
161 <para>
162 Removes @len characters from a #GString, starting at position @pos.
163 The rest of the #GString is shifted down to fill the gap.
164 </para>
165
166 @string: a #GString.
167 @pos: the position of the characters to remove.
168 @len: the number of characters to remove.
169 @Returns: the #GString.
170
171
172 <!-- ##### FUNCTION g_string_truncate ##### -->
173 <para>
174 Cuts off the end of the GString, leaving the first @len characters.
175 </para>
176
177 @string: a #GString.
178 @len: the new size of the #GString.
179 @Returns: the #GString.
180
181
182 <!-- ##### FUNCTION g_string_free ##### -->
183 <para>
184 Frees the memory allocated for the #GString.
185 If free_segment is TRUE it also frees the character data.
186 </para>
187
188 @string: a #GString.
189 @free_segment: if TRUE the actual character data is freed as well.
190
191
192 <!-- ##### FUNCTION g_string_up ##### -->
193 <para>
194 Converts a #GString to upper case.
195 </para>
196
197 @string: a #GString.
198 @Returns: the #GString.
199
200
201 <!-- ##### FUNCTION g_string_down ##### -->
202 <para>
203 Converts a #GString to lower case.
204 </para>
205
206 @string: a #GString.
207 @Returns: the #GString.
208
209