Mercurial > hg > th-libs
comparison th_string.c @ 702:5653e386730b
Fix th_strpbrk().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2020 23:37:22 +0200 |
parents | d687bbb54c1a |
children | d289fae3c1a8 |
comparison
equal
deleted
inserted
replaced
701:d687bbb54c1a | 702:5653e386730b |
---|---|
12 #include "th_printf.c" | 12 #include "th_printf.c" |
13 | 13 |
14 | 14 |
15 /** | 15 /** |
16 * Implementation of strchr() for th_char_t. | 16 * Implementation of strchr() for th_char_t. |
17 * @param[in] src string to find 'ch' from | 17 * @param[in] src string to find @p valid from |
18 * @returns pointer to the match position, NULL if no match found | 18 * @returns pointer to the match position, NULL if no match found |
19 */ | 19 */ |
20 th_char_t *th_strchr(const th_char_t *str, const th_char_t ch) | 20 th_char_t *th_strchr(const th_char_t *str, const th_char_t valid) |
21 { | 21 { |
22 for (th_char_t *p = (th_char_t *) str; *p; p++) | 22 for (th_char_t *ch = (th_char_t *) str; *ch; ch++) |
23 { | 23 { |
24 if (*p == ch) | 24 if (*ch == valid) |
25 return p; | 25 return ch; |
26 } | 26 } |
27 return NULL; | 27 return NULL; |
28 } | 28 } |
29 | 29 |
30 | 30 |
33 * @param[in] src string to find any th_char_t in @p valid from | 33 * @param[in] src string to find any th_char_t in @p valid from |
34 * @returns pointer to the match position, NULL if no match found | 34 * @returns pointer to the match position, NULL if no match found |
35 */ | 35 */ |
36 th_char_t *th_strpbrk(const th_char_t *str, const th_char_t *valid) | 36 th_char_t *th_strpbrk(const th_char_t *str, const th_char_t *valid) |
37 { | 37 { |
38 for (th_char_t *p = (th_char_t *) str; *p; p++) | 38 for (th_char_t *ch = (th_char_t *) str; *ch; ch++) |
39 { | 39 { |
40 for (const th_char_t *ch = valid; *valid; valid++) | 40 for (const th_char_t *cmp = valid; *cmp; cmp++) |
41 { | 41 { |
42 if (*p == *ch) | 42 if (*ch == *cmp) |
43 return p; | 43 return ch; |
44 } | 44 } |
45 } | 45 } |
46 return NULL; | 46 return NULL; |
47 } | 47 } |
48 | 48 |