src/ucx/string.h

branch
constsstr
changeset 276
f1b2146d4805
parent 275
96f643d30ff1
child 288
6af5798342e8
equal deleted inserted replaced
275:96f643d30ff1 276:f1b2146d4805
262 * 262 *
263 * @see sstrsubs() 263 * @see sstrsubs()
264 */ 264 */
265 sstr_t sstrrchr(sstr_t string, int chr); 265 sstr_t sstrrchr(sstr_t string, int chr);
266 266
267
268 const char* ucx_strstr(
269 const char *str,
270 size_t length,
271 const char *match,
272 size_t matchlen,
273 size_t *newlen);
274
267 /** 275 /**
268 * Returns a substring starting at the location of the first occurrence of the 276 * Returns a substring starting at the location of the first occurrence of the
269 * specified string. 277 * specified string.
270 * 278 *
271 * If the string does not contain the other string, an empty string is returned. 279 * If the string does not contain the other string, an empty string is returned.
277 * @param match string containing the sequence of characters to match 285 * @param match string containing the sequence of characters to match
278 * @return a substring starting at the first occurrence of 286 * @return a substring starting at the first occurrence of
279 * <code>match</code>, or an empty string, if the sequence is not 287 * <code>match</code>, or an empty string, if the sequence is not
280 * present in <code>string</code> 288 * present in <code>string</code>
281 */ 289 */
282 sstr_t sstrstr(sstr_t string, sstr_t match); 290 sstr_t ucx_sstrstr(sstr_t string, scstr_t match);
291 #define sstrstr(string, match) ucx_sstrstr(string, SCSTR(match))
292
293 scstr_t ucx_scstrstr(scstr_t string, scstr_t match);
294 #define scstrstr(string, match) ucx_scstrstr(string, SCSTR(match))
283 295
284 /** 296 /**
285 * Splits a string into parts by using a delimiter string. 297 * Splits a string into parts by using a delimiter string.
286 * 298 *
287 * This function will return <code>NULL</code>, if one of the following happens: 299 * This function will return <code>NULL</code>, if one of the following happens:
326 * @return a sstr_t array containing the split strings or 338 * @return a sstr_t array containing the split strings or
327 * <code>NULL</code> on error 339 * <code>NULL</code> on error
328 * 340 *
329 * @see sstrsplit_a() 341 * @see sstrsplit_a()
330 */ 342 */
331 sstr_t* sstrsplit(sstr_t string, sstr_t delim, ssize_t *count); 343 sstr_t* ucx_strsplit(scstr_t string, scstr_t delim, ssize_t *count);
344
345 #define sstrsplit(s, delim, count) ucx_strsplit(SCSTR(s), SCSTR(delim), count)
332 346
333 /** 347 /**
334 * Performing sstrsplit() using a UcxAllocator. 348 * Performing sstrsplit() using a UcxAllocator.
335 * 349 *
336 * <i>Read the description of sstrsplit() for details.</i> 350 * <i>Read the description of sstrsplit() for details.</i>
350 * @return a sstr_t array containing the split strings or 364 * @return a sstr_t array containing the split strings or
351 * <code>NULL</code> on error 365 * <code>NULL</code> on error
352 * 366 *
353 * @see sstrsplit() 367 * @see sstrsplit()
354 */ 368 */
355 sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t string, sstr_t delim, 369 sstr_t* ucx_strsplit_a(UcxAllocator *allocator, scstr_t string, scstr_t delim,
356 ssize_t *count); 370 ssize_t *count);
371
372 #define sstrsplit_a(a, s, d, c) ucx_strsplit_a(a, SCSTR(s), SCSTR(d, c))
357 373
358 /** 374 /**
359 * Compares two UCX strings with standard <code>memcmp()</code>. 375 * Compares two UCX strings with standard <code>memcmp()</code>.
360 * 376 *
361 * At first it compares the sstr_t.length attribute of the two strings. The 377 * At first it compares the sstr_t.length attribute of the two strings. The
365 * @param s2 the second string 381 * @param s2 the second string
366 * @return -1, if the length of s1 is less than the length of s2 or 1, if the 382 * @return -1, if the length of s1 is less than the length of s2 or 1, if the
367 * length of s1 is greater than the length of s2 or the result of 383 * length of s1 is greater than the length of s2 or the result of
368 * <code>memcmp()</code> otherwise (i.e. 0 if the strings match) 384 * <code>memcmp()</code> otherwise (i.e. 0 if the strings match)
369 */ 385 */
370 int sstrcmp(sstr_t s1, sstr_t s2); 386 int ucx_str_cmp(scstr_t s1, scstr_t s2);
387
388 #define sstrcmp(s1, s2) ucx_str_cmp(SCSTR(s1), SCSTR(s2))
371 389
372 /** 390 /**
373 * Compares two UCX strings ignoring the case. 391 * Compares two UCX strings ignoring the case.
374 * 392 *
375 * At first it compares the sstr_t.length attribute of the two strings. If and 393 * At first it compares the sstr_t.length attribute of the two strings. If and
381 * @return -1, if the length of s1 is less than the length of s2 or 1, if the 399 * @return -1, if the length of s1 is less than the length of s2 or 1, if the
382 * length of s1 is greater than the length of s2 or the difference between the 400 * length of s1 is greater than the length of s2 or the difference between the
383 * first two differing characters otherwise (i.e. 0 if the strings match and 401 * first two differing characters otherwise (i.e. 0 if the strings match and
384 * no characters differ) 402 * no characters differ)
385 */ 403 */
386 int sstrcasecmp(sstr_t s1, sstr_t s2); 404 int ucx_str_casecmp(scstr_t s1, scstr_t s2);
405
406 #define sstrcasecmp(s1, s2) ucx_str_casecmp(SCSTR(s1), SCSTR(s2))
387 407
388 /** 408 /**
389 * Creates a duplicate of the specified string. 409 * Creates a duplicate of the specified string.
390 * 410 *
391 * The new sstr_t will contain a copy allocated by standard 411 * The new sstr_t will contain a copy allocated by standard
420 * @see sstrdup() 440 * @see sstrdup()
421 */ 441 */
422 sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t string); 442 sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t string);
423 443
424 #define sstrdup_a(allocator, s) scstrdup_a(allocator, SCSTR(s)) 444 #define sstrdup_a(allocator, s) scstrdup_a(allocator, SCSTR(s))
445
446
447 size_t ucx_strtrim(const char *str, size_t length, size_t *newlen);
425 448
426 /** 449 /**
427 * Omits leading and trailing spaces. 450 * Omits leading and trailing spaces.
428 * 451 *
429 * This function returns a new sstr_t containing a trimmed version of the 452 * This function returns a new sstr_t containing a trimmed version of the
440 * @param string the string that shall be trimmed 463 * @param string the string that shall be trimmed
441 * @return a new sstr_t containing the trimmed string 464 * @return a new sstr_t containing the trimmed string
442 */ 465 */
443 sstr_t sstrtrim(sstr_t string); 466 sstr_t sstrtrim(sstr_t string);
444 467
468 scstr_t scstrtrim(scstr_t string);
469
445 /** 470 /**
446 * Checks, if a string has a specific prefix. 471 * Checks, if a string has a specific prefix.
447 * @param string the string to check 472 * @param string the string to check
448 * @param prefix the prefix the string should have 473 * @param prefix the prefix the string should have
449 * @return 1, if and only if the string has the specified prefix, 0 otherwise 474 * @return 1, if and only if the string has the specified prefix, 0 otherwise

mercurial