changeset 701:d687bbb54c1a

Add th_strpbrk().
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 10 Mar 2020 21:06:09 +0200
parents ec8fe89576ff
children 5653e386730b
files th_string.c th_string.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- 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);