]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: Add the function isteqi
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 Jun 2018 14:33:53 +0000 (16:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Jul 2018 11:39:30 +0000 (13:39 +0200)
This new function does the same as isteq, but ignoring the case.

include/common/ist.h

index bd98ab008a0a892047cc8a0b647d59faeb2201dc..7c60c68f3c20ce8ab398c039df77d5a33af4a9e5 100644 (file)
@@ -28,6 +28,7 @@
 #ifndef _COMMON_IST_H
 #define _COMMON_IST_H
 
+#include <ctype.h>
 #include <string.h>
 
 #include <common/config.h>
@@ -243,6 +244,24 @@ static inline int isteq(const struct ist ist1, const struct ist ist2)
        return 1;
 }
 
+/* returns non-zero if <ist1> equals <ist2>, ignoring the case (empty strings are equal) */
+static inline int isteqi(const struct ist ist1, const struct ist ist2)
+{
+       struct ist l = ist1;
+       struct ist r = ist2;
+
+       if (l.len != r.len)
+               return 0;
+
+       while (l.len--) {
+               if (tolower(*l.ptr) != tolower(*r.ptr))
+                       return 0;
+               l.ptr++;
+               r.ptr++;
+       }
+       return 1;
+}
+
 /* returns non-zero if <ist1> equals <ist2> on the first <count> characters
  * (empty strings are equal).
  */