Mercurial > hg > th-libs
diff th_string.h @ 679:83a48de05fe9
Add in th_strlen() which is a custom function if TH_CHAR_TYPE is defined.
Otherwise th_strlen() is defined as a macro alias to libc strlen().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2020 19:45:26 +0200 |
parents | dfabc7eef3dd |
children | 39c82d877251 |
line wrap: on
line diff
--- a/th_string.h Sat Feb 29 12:19:02 2020 +0200 +++ b/th_string.h Wed Mar 04 19:45:26 2020 +0200 @@ -111,6 +111,26 @@ /* Normal NUL-terminated string functions */ +#ifdef TH_CHAR_TYPE +/** + * Implementation of strlen() that uses th_char_t type. Not optimized. + * @param[in] src string to get length of + * @returns length of the string in number of th_char_t units. + */ +size_t th_strlen(const th_char_t *str) +{ + size_t len = 0; + assert(str != NULL); + + while (str[len]) len++; + + return len; +} +#else +#define th_strlen(xd) strlen(xd) +#endif + + 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);