comparison th_string.c @ 687:5a7254b78614

Add th_strchr().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2020 14:26:45 +0200
parents d8738bfad0a8
children 953e16582f25
comparison
equal deleted inserted replaced
686:dfc2c9f0577f 687:5a7254b78614
8 #include "th_util.h" 8 #include "th_util.h"
9 #include "th_string.h" 9 #include "th_string.h"
10 10
11 // Include printf implementation 11 // Include printf implementation
12 #include "th_printf.c" 12 #include "th_printf.c"
13
14
15 /**
16 * Implementation of strchr() for th_char_t.
17 * @param[in] src string to find 'ch' from
18 * @returns pointer to the match position, NULL if no match found
19 */
20 th_char_t *th_strchr(const th_char_t *str, const th_char_t ch)
21 {
22 for (th_char_t *p = (th_char_t *) str; *p; p++)
23 {
24 if (*p == ch)
25 return p;
26 }
27 return NULL;
28 }
13 29
14 30
15 /** 31 /**
16 * Implementation of strdup() with a @c NULL check. 32 * Implementation of strdup() with a @c NULL check.
17 * @param[in] src string to create a copy of 33 * @param[in] src string to create a copy of
571 { 587 {
572 // Split foremost str element out 588 // Split foremost str element out
573 match = FALSE; 589 match = FALSE;
574 for (end = start; str[end] != 0; end++) 590 for (end = start; str[end] != 0; end++)
575 { 591 {
576 for (size_t n = 0; sep[n]; n++) 592 if (th_strchr(sep, str[end]))
577 if (sep[n] == str[end])
578 { 593 {
579 match = TRUE; 594 match = TRUE;
580 break; 595 break;
581 } 596 }
582 } 597 }