]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: standard: Add my_memspn and my_memcspn
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 15 Apr 2020 08:23:01 +0000 (10:23 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:38 +0000 (09:39 +0200)
Do the same than strsnp() and strcspn() but on a raw bytes buffer.

include/common/standard.h
src/standard.c

index a6c39104c98c0c3411867cc7978462c8b9ec9677..40991fa45127363da17d199ef771410132ea4c50 100644 (file)
@@ -1006,6 +1006,16 @@ char *my_strndup(const char *src, int n);
  */
 const void *my_memmem(const void *, size_t, const void *, size_t);
 
+/* get length of the initial segment consiting entirely of bytes within a given
+ * mask
+ */
+size_t my_memspn(const void *, size_t, const void *, size_t);
+
+/* get length of the initial segment consiting entirely of bytes not within a
+ * given mask
+ */
+size_t my_memcspn(const void *, size_t, const void *, size_t);
+
 /* This function returns the first unused key greater than or equal to <key> in
  * ID tree <root>. Zero is returned if no place is found.
  */
index cf2724846ce6b15dd4c8c2df0f5bf57a6c0b0453..1bca31816a730d7fe1b6bbb445d169d3e9966dfc 100644 (file)
@@ -2292,6 +2292,32 @@ const void *my_memmem(const void *haystack, size_t haystacklen, const void *need
        return NULL;
 }
 
+/* get length of the initial segment consiting entirely of bytes in <accept> */
+size_t my_memspn(const void *str, size_t len, const void *accept, size_t acceptlen)
+{
+       size_t ret = 0;
+
+       while (ret < len && memchr(accept, *((int *)str), acceptlen)) {
+               str++;
+               ret++;
+       }
+       return ret;
+}
+
+/* get length of the initial segment consiting entirely of bytes not in <rejcet> */
+size_t my_memcspn(const void *str, size_t len, const void *reject, size_t rejectlen)
+{
+       size_t ret = 0;
+
+       while (ret < len) {
+               if(memchr(reject, *((int *)str), rejectlen))
+                       return ret;
+               str++;
+               ret++;
+       }
+       return ret;
+}
+
 /* This function returns the first unused key greater than or equal to <key> in
  * ID tree <root>. Zero is returned if no place is found.
  */