# HG changeset patch # User Matti Hamalainen # Date 1583867169 -7200 # Node ID d687bbb54c1a767927038a961165ef32e8276d26 # Parent ec8fe89576ff6a4411bea7aaa644e243f4f545bd Add th_strpbrk(). diff -r ec8fe89576ff -r d687bbb54c1a th_string.c --- 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. diff -r ec8fe89576ff -r d687bbb54c1a th_string.h --- a/th_string.h Tue Mar 10 17:01:10 2020 +0200 +++ b/th_string.h Tue Mar 10 21:06:09 2020 +0200 @@ -139,6 +139,7 @@ th_char_t *th_strchr(const th_char_t *str, const th_char_t ch); +th_char_t *th_strpbrk(const th_char_t *str, const th_char_t *valid); th_char_t *th_strdup(const th_char_t *src); th_char_t *th_strndup(const th_char_t *src, const size_t n); th_char_t *th_strdup_trim(const th_char_t *src, const int flags);