diff th_string.c @ 687:5a7254b78614

Add th_strchr().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2020 14:26:45 +0200
parents d8738bfad0a8
children 953e16582f25
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;