Mercurial > hg > th-libs
changeset 687:5a7254b78614
Add th_strchr().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Mar 2020 14:26:45 +0200 |
parents | dfc2c9f0577f |
children | a54298eef91a |
files | th_string.c th_string.h |
diffstat | 2 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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);