# HG changeset patch # User Matti Hamalainen # Date 1583497605 -7200 # Node ID 5a7254b786148fa2f685833948d2c2bdcff98c03 # Parent dfc2c9f0577ff392e97e377dd1a0b54ce26ef310 Add th_strchr(). diff -r dfc2c9f0577f -r 5a7254b78614 th_string.c --- a/th_string.c Fri Mar 06 00:16:30 2020 +0200 +++ b/th_string.c Fri Mar 06 14:26:45 2020 +0200 @@ -13,6 +13,22 @@ /** + * Implementation of strchr() for th_char_t. + * @param[in] src string to find 'ch' from + * @returns pointer to the match position, NULL if no match found + */ +th_char_t *th_strchr(const th_char_t *str, const th_char_t ch) +{ + for (th_char_t *p = (th_char_t *) str; *p; p++) + { + 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. @@ -573,8 +589,7 @@ match = FALSE; for (end = start; str[end] != 0; end++) { - for (size_t n = 0; sep[n]; n++) - if (sep[n] == str[end]) + if (th_strchr(sep, str[end])) { match = TRUE; break; diff -r dfc2c9f0577f -r 5a7254b78614 th_string.h --- a/th_string.h Fri Mar 06 00:16:30 2020 +0200 +++ b/th_string.h Fri Mar 06 14:26:45 2020 +0200 @@ -138,6 +138,7 @@ #endif +th_char_t *th_strchr(const th_char_t *str, const th_char_t ch); 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);