ucx/string.h

changeset 119
baa839a7633f
parent 118
151f5345f303
child 123
7fb0f74517c5
equal deleted inserted replaced
118:151f5345f303 119:baa839a7633f
117 * @return the cumulated length of all strings 117 * @return the cumulated length of all strings
118 */ 118 */
119 size_t sstrnlen(size_t count, sstr_t string, ...); 119 size_t sstrnlen(size_t count, sstr_t string, ...);
120 120
121 121
122 /* 122 /**
123 * concatenates n strings 123 * Concatenates strings.
124 * 124 *
125 * n number of strings 125 * At least one string must be specified and there must be enough memory
126 * s new string with enough memory allocated 126 * available referenced by the destination sstr_t.ptr for this function to
127 * ... strings 127 * successfully concatenate all specified strings.
128 */ 128 *
129 sstr_t sstrncat(size_t n, sstr_t s, sstr_t c1, ...); 129 * The sstr_t.length of the destination string specifies the capacity and
130 130 * should match the total memory available referenced by the destination
131 131 * sstr_t.ptr. This function <i>never</i> copies data beyond the capacity and
132 /* 132 * does not modify any of the source strings.
133 * 133 *
134 */ 134 * <b>Attention:</b>
135 sstr_t sstrsubs(sstr_t s, size_t start); 135 * <ul>
136 136 * <li>Any content in the destination string will be overwritten</li>
137 /* 137 * <li>The destination sstr_t.ptr is <b>NOT</b>
138 * 138 * <code>NULL</code>-terminated</li>
139 */ 139 * <li>The destination sstr_t.length is set to the total length of the
140 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length); 140 * concatenated strings</li>
141 141 * <li><i>Hint:</i> get a <code>NULL</code>-terminated string by performing
142 /* 142 * <code>mystring.ptr[mystring.length]='\0'</code> after calling this
143 * 143 * function</li>
144 */ 144 * </ul>
145 sstr_t sstrchr(sstr_t s, int c); 145 *
146 146 * @param count the total number of strings to concatenate
147 /* 147 * @param dest new sstr_t with capacity information and allocated memory
148 * splits s into n parts 148 * @param src the first string
149 * 149 * @param ... all other strings
150 * s the string to split 150 * @return the argument for <code>dest</code> is returned
151 * d the delimiter string 151 */
152 * n the maximum size of the resulting list 152 sstr_t sstrncat(size_t count, sstr_t dest, sstr_t src, ...);
153 * a size of 0 indicates an unbounded list size 153
154 * the actual size of the list will be stored here 154
155 * 155 /**
156 * Hint: use this value to avoid dynamic reallocation of the result list 156 * Returns a substring starting at the specified location.
157 * 157 *
158 * Returns a list of the split strings 158 * <b>Attention:</b> the new string references the same memory area as the
159 * NOTE: this list needs to be freed manually after usage 159 * input string and will <b>NOT</b> be <code>NULL</code>-terminated.
160 * 160 * Use sstrdup() to get a copy.
161 * Returns NULL on error 161 *
162 */ 162 * @param string input string
163 sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n); 163 * @param start start location of the substring
164 * @return a substring of <code>string</code> starting at <code>start</code>
165 *
166 * @see sstrsubsl()
167 * @see sstrchr()
168 */
169 sstr_t sstrsubs(sstr_t string, size_t start);
170
171 /**
172 * Returns a substring with a maximum length starting at the specified location.
173 *
174 * <b>Attention:</b> the new string references the same memory area as the
175 * input string and will <b>NOT</b> be <code>NULL</code>-terminated.
176 * Use sstrdup() to get a copy.
177 *
178 * @param string input string
179 * @param start start location of the substring
180 * @param length the maximum length of the substring
181 * @return a substring of <code>string</code> starting at <code>start</code>
182 * with a maximum length of <code>length</code>
183 *
184 * @see sstrsubs()
185 * @see sstrchr()
186 */
187 sstr_t sstrsubsl(sstr_t string, size_t start, size_t length);
188
189 /**
190 * Returns a substring starting at the location of the first occurrence of the
191 * specified character.
192 *
193 * If the string does not contain the character, an empty string is returned.
194 *
195 * @param string the string where to locate the character
196 * @param chr the character to locate
197 * @return a substring starting at the least location of <code>chr</code>
198 *
199 * @see sstrsubs()
200 */
201 sstr_t sstrchr(sstr_t string, int chr);
202
203 /**
204 * Splits a string into parts by using a delimiter string.
205 *
206 * This function will return <code>NULL</code>, if one of the following happens:
207 * <ul>
208 * <li>the string length is zero</li>
209 * <li>the delimeter length is zero</li>
210 * <li>the string equals the delimeter</li>
211 * <li>memory allocation fails</li>
212 * </ul>
213 *
214 * The integer referenced by <code>count</code> is used as input and determines
215 * the maximum size of the resulting list, i.e. the maximum count of splits to
216 * perform + 1.
217 *
218 * The integer referenced by <code>count</code> is also used as output and is
219 * set to
220 * <ul>
221 * <li>-2, on memory allocation errors</li>
222 * <li>-1, if either the string or the delimiter is an empty string</li>
223 * <li>0, if the string equals the delimiter</li>
224 * <li>1, if the string does not contain the delimiter</li>
225 * <li>the count of list items, otherwise</li>
226 * </ul>
227 *
228 * If the string starts with the delimiter, the first item of the resulting
229 * list will be an empty string.
230 *
231 * If the string ends with the delimiter and the maximum list size is not
232 * exceeded, the last list item will be an empty string.
233 *
234 * <b>Attention:</b> All list items <b>AND</b> all sstr_t.ptr of the list
235 * items must be manually passed to <code>free()</code>. Use sstrsplita() with
236 * an allocator to managed memory, to avoid this.
237 *
238 * @param string the string to split
239 * @param delim the delimiter string
240 * @param count IN: the maximum size of the resulting list (0 for an
241 * unbounded list), OUT: the actual size of the list
242 * @return a list of the split strings as sstr_t array or
243 * <code>NULL</code> on error
244 *
245 * @see sstrsplita()
246 */
247 sstr_t* sstrsplit(sstr_t string, sstr_t delim, size_t *count);
248
249 /**
250 * Performing sstrsplit() using an UcxAllocator.
251 *
252 * <i>Read the description of sstrsplit() for details.</i>
253 *
254 * The memory for the sstr_t.ptr pointers of the list items and the memory for
255 * the sstr_t array itself are allocated by using the UcxAllocator.malloc()
256 * function.
257 *
258 * <b>Note:</b> the allocator is not used for memory that is freed within the
259 * same call of this function (locally scoped variables).
260 *
261 * @param string the string to split
262 * @param delim the delimiter string
263 * @param count IN: the maximum size of the resulting list (0 for an
264 * unbounded list), OUT: the actual size of the list
265 * @param allocator the UcxAllocator used for allocating memory
266 * @return a list of the split strings as sstr_t array or
267 * <code>NULL</code> on error
268 *
269 * @see sstrsplit()
270 */
271 sstr_t* sstrsplita(sstr_t string, sstr_t delim, size_t *count,
272 UcxAllocator *allocator);
164 273
165 /** 274 /**
166 * Compares two UCX strings with standard <code>memcmp()</code>. 275 * Compares two UCX strings with standard <code>memcmp()</code>.
167 * 276 *
168 * At first it compares the sstr_t.length attribute of the two strings. The 277 * At first it compares the sstr_t.length attribute of the two strings. The
186 * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- 295 * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>-
187 * terminated. 296 * terminated.
188 * 297 *
189 * @param string the string to duplicate 298 * @param string the string to duplicate
190 * @return a duplicate of the string 299 * @return a duplicate of the string
300 * @see sstrdupa()
191 */ 301 */
192 sstr_t sstrdup(sstr_t string); 302 sstr_t sstrdup(sstr_t string);
193 303
194 /** 304 /**
195 * Creates a duplicate of the specified string using an UcxAllocator. 305 * Creates a duplicate of the specified string using an UcxAllocator.
203 * terminated. 313 * terminated.
204 * 314 *
205 * @param allocator a valid instance of an UcxAllocator 315 * @param allocator a valid instance of an UcxAllocator
206 * @param string the string to duplicate 316 * @param string the string to duplicate
207 * @return a duplicate of the string 317 * @return a duplicate of the string
318 * @see sstrdup()
208 */ 319 */
209 sstr_t sstrdupa(UcxAllocator *allocator, sstr_t string); 320 sstr_t sstrdupa(UcxAllocator *allocator, sstr_t string);
210 321
211 /** 322 /**
212 * Omits leading and trailing spaces. 323 * Omits leading and trailing spaces.

mercurial