Mercurial > hg > th-libs
diff th_string.c @ 701:d687bbb54c1a
Add th_strpbrk().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2020 21:06:09 +0200 |
parents | 9bbacd72df3d |
children | 5653e386730b |
line wrap: on
line diff
--- a/th_string.c Tue Mar 10 17:01:10 2020 +0200 +++ b/th_string.c Tue Mar 10 21:06:09 2020 +0200 @@ -29,6 +29,25 @@ /** + * Implementation of strpbrk() for th_char_t. + * @param[in] src string to find any th_char_t in @p valid from + * @returns pointer to the match position, NULL if no match found + */ +th_char_t *th_strpbrk(const th_char_t *str, const th_char_t *valid) +{ + for (th_char_t *p = (th_char_t *) str; *p; p++) + { + for (const th_char_t *ch = valid; *valid; valid++) + { + if (*p == *ch) + return p; + } + } + return NULL; +} + + +/** * Implementation of strdup() with a @c NULL check. * @param[in] src string to create a copy of * @returns copy of the given string, or @c NULL if @p src was @c NULL or memory could not be allocated.