]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: Add a case insensitive istmatch function
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Wed, 28 Oct 2020 10:35:14 +0000 (11:35 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Fri, 30 Oct 2020 12:20:21 +0000 (13:20 +0100)
Add a helper function that checks if a string starts with another string
while ignoring case.

include/import/ist.h

index 08e2119382c1069bbb0ce5003ce8209a921cc1f1..4c8979b423d6dfb2a7d3ce3dad58fdb6cc493a8c 100644 (file)
@@ -315,6 +315,26 @@ static inline int istmatch(const struct ist ist1, const struct ist ist2)
        return 1;
 }
 
+/* returns non-zero if <ist1> starts like <ist2>, ignoring the case (empty strings do match) */
+static inline int istmatchi(const struct ist ist1, const struct ist ist2)
+{
+       struct ist l = ist1;
+       struct ist r = ist2;
+
+       if (l.len < r.len)
+               return 0;
+
+       while (r.len--) {
+               if (*l.ptr != *r.ptr &&
+                   ist_lc[(unsigned char)*l.ptr] != ist_lc[(unsigned char)*r.ptr])
+                       return 0;
+
+               l.ptr++;
+               r.ptr++;
+       }
+       return 1;
+}
+
 /* returns non-zero if <ist1> starts like <ist2> on the first <count>
  * characters (empty strings do match).
  */