From: Christopher Faulet Date: Tue, 6 Aug 2019 14:55:52 +0000 (+0200) Subject: MINOR: istbuf: Add the function b_isteqi() X-Git-Tag: v2.1-dev2~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=130cf2170992647b21a635b8e7b4ff0a8cb3b5ac;p=thirdparty%2Fhaproxy.git MINOR: istbuf: Add the function b_isteqi() This function compares a part of a buffer to an indirect string (ist), ignoring the case of the characters. --- diff --git a/include/common/istbuf.h b/include/common/istbuf.h index 274bf5ea81..9b6ce7c6bd 100644 --- a/include/common/istbuf.h +++ b/include/common/istbuf.h @@ -64,6 +64,29 @@ static inline ssize_t b_isteq(const struct buffer *b, size_t o, size_t n, const return ist.len; } +/* Same as b_isteq but case-insensitive */ +static inline ssize_t b_isteqi(const struct buffer *b, size_t o, size_t n, const struct ist ist) +{ + struct ist r = ist; + const char *p; + const char *end = b_wrap(b); + + if (n < r.len) + return 0; + + p = b_peek(b, o); + while (r.len--) { + if (*p != *r.ptr && + ist_lc[(unsigned char)*p] != ist_lc[(unsigned char)*r.ptr]) + return -1; + p++; + r.ptr++; + if (unlikely(p == end)) + p = b_orig(b); + } + return ist.len; +} + /* b_isteat() : "eats" string from the head of buffer . Wrapping data * is explicitly supported. It matches a single byte per iteration so strings * should remain reasonably small. Returns :