]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: istbuf: Add the function b_isteqi()
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 6 Aug 2019 14:55:52 +0000 (16:55 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Sep 2019 08:18:54 +0000 (10:18 +0200)
This function compares a part of a buffer to an indirect string (ist), ignoring
the case of the characters.

include/common/istbuf.h

index 274bf5ea815a72207f3d6e7959020defb22effe9..9b6ce7c6bdf4ea9918225fedf56473297c78d843 100644 (file)
@@ -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 <ist> from the head of buffer <b>. Wrapping data
  * is explicitly supported. It matches a single byte per iteration so strings
  * should remain reasonably small. Returns :