ucx/string.h

changeset 152
62921b370c60
parent 124
80609f9675f1
equal deleted inserted replaced
151:11f3bb408051 152:62921b370c60
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2015 Olaf Wintermann. All rights reserved. 4 * Copyright 2016 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
135 * @return the concatenated string 135 * @return the concatenated string
136 */ 136 */
137 sstr_t sstrcat(size_t count, sstr_t s1, sstr_t s2, ...); 137 sstr_t sstrcat(size_t count, sstr_t s1, sstr_t s2, ...);
138 138
139 /** 139 /**
140 * Concatenates two or more strings using an UcxAllocator. 140 * Concatenates two or more strings using a UcxAllocator.
141 * 141 *
142 * See sstrcat() for details. 142 * See sstrcat() for details.
143 * 143 *
144 * @param a the allocator to use 144 * @param a the allocator to use
145 * @param count the total number of strings to concatenate 145 * @param count the total number of strings to concatenate
210 * @return a substring starting at the last location of <code>chr</code> 210 * @return a substring starting at the last location of <code>chr</code>
211 * 211 *
212 * @see sstrsubs() 212 * @see sstrsubs()
213 */ 213 */
214 sstr_t sstrrchr(sstr_t string, int chr); 214 sstr_t sstrrchr(sstr_t string, int chr);
215
216 /**
217 * Returns a substring starting at the location of the first occurrence of the
218 * specified string.
219 *
220 * If the string does not contain the other string, an empty string is returned.
221 *
222 * If <code>match</code> is an empty string, the complete <code>string</code> is
223 * returned.
224 *
225 * @param string the string to be scanned
226 * @param match string containing the sequence of characters to match
227 * @return a substring starting at the first occurrence of
228 * <code>match</code>, or an empty string, if the sequence is not
229 * present in <code>string</code>
230 */
231 sstr_t sstrstr(sstr_t string, sstr_t match);
215 232
216 /** 233 /**
217 * Splits a string into parts by using a delimiter string. 234 * Splits a string into parts by using a delimiter string.
218 * 235 *
219 * This function will return <code>NULL</code>, if one of the following happens: 236 * This function will return <code>NULL</code>, if one of the following happens:
241 * If the string starts with the delimiter, the first item of the resulting 258 * If the string starts with the delimiter, the first item of the resulting
242 * array will be an empty string. 259 * array will be an empty string.
243 * 260 *
244 * If the string ends with the delimiter and the maximum list size is not 261 * If the string ends with the delimiter and the maximum list size is not
245 * exceeded, the last array item will be an empty string. 262 * exceeded, the last array item will be an empty string.
263 * In case the list size would be exceeded, the last array item will be the
264 * remaining string after the last split, <i>including</i> the terminating
265 * delimiter.
246 * 266 *
247 * <b>Attention:</b> The array pointer <b>AND</b> all sstr_t.ptr of the array 267 * <b>Attention:</b> The array pointer <b>AND</b> all sstr_t.ptr of the array
248 * items must be manually passed to <code>free()</code>. Use sstrsplit_a() with 268 * items must be manually passed to <code>free()</code>. Use sstrsplit_a() with
249 * an allocator to managed memory, to avoid this. 269 * an allocator to managed memory, to avoid this.
250 * 270 *
258 * @see sstrsplit_a() 278 * @see sstrsplit_a()
259 */ 279 */
260 sstr_t* sstrsplit(sstr_t string, sstr_t delim, ssize_t *count); 280 sstr_t* sstrsplit(sstr_t string, sstr_t delim, ssize_t *count);
261 281
262 /** 282 /**
263 * Performing sstrsplit() using an UcxAllocator. 283 * Performing sstrsplit() using a UcxAllocator.
264 * 284 *
265 * <i>Read the description of sstrsplit() for details.</i> 285 * <i>Read the description of sstrsplit() for details.</i>
266 * 286 *
267 * The memory for the sstr_t.ptr pointers of the array items and the memory for 287 * The memory for the sstr_t.ptr pointers of the array items and the memory for
268 * the sstr_t array itself are allocated by using the UcxAllocator.malloc() 288 * the sstr_t array itself are allocated by using the UcxAllocator.malloc()
329 * @see sstrdup_a() 349 * @see sstrdup_a()
330 */ 350 */
331 sstr_t sstrdup(sstr_t string); 351 sstr_t sstrdup(sstr_t string);
332 352
333 /** 353 /**
334 * Creates a duplicate of the specified string using an UcxAllocator. 354 * Creates a duplicate of the specified string using a UcxAllocator.
335 * 355 *
336 * The new sstr_t will contain a copy allocated by the allocators 356 * The new sstr_t will contain a copy allocated by the allocators
337 * ucx_allocator_malloc function. So it is implementation depended, whether the 357 * ucx_allocator_malloc function. So it is implementation depended, whether the
338 * returned sstr_t.ptr pointer must be passed to the allocators 358 * returned sstr_t.ptr pointer must be passed to the allocators
339 * ucx_allocator_free function manually. 359 * ucx_allocator_free function manually.
340 * 360 *
341 * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>- 361 * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>-
342 * terminated. 362 * terminated.
343 * 363 *
344 * @param allocator a valid instance of an UcxAllocator 364 * @param allocator a valid instance of a UcxAllocator
345 * @param string the string to duplicate 365 * @param string the string to duplicate
346 * @return a duplicate of the string 366 * @return a duplicate of the string
347 * @see sstrdup() 367 * @see sstrdup()
348 */ 368 */
349 sstr_t sstrdup_a(UcxAllocator *allocator, sstr_t string); 369 sstr_t sstrdup_a(UcxAllocator *allocator, sstr_t string);

mercurial