From: Christopher Faulet Date: Wed, 15 Apr 2020 08:23:01 +0000 (+0200) Subject: MINOR: standard: Add my_memspn and my_memcspn X-Git-Tag: v2.2-dev7~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5eb96cbcbc5fecb9d1275ff442e579e97a7f8c2e;p=thirdparty%2Fhaproxy.git MINOR: standard: Add my_memspn and my_memcspn Do the same than strsnp() and strcspn() but on a raw bytes buffer. --- diff --git a/include/common/standard.h b/include/common/standard.h index a6c39104c9..40991fa451 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -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 in * ID tree . Zero is returned if no place is found. */ diff --git a/src/standard.c b/src/standard.c index cf2724846c..1bca31816a 100644 --- a/src/standard.c +++ b/src/standard.c @@ -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 */ +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 */ +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 in * ID tree . Zero is returned if no place is found. */