From: Remi Tricot-Le Breton Date: Wed, 28 Oct 2020 10:35:14 +0000 (+0100) Subject: MINOR: ist: Add a case insensitive istmatch function X-Git-Tag: v2.1.10~11 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=7f8f26b26309beb0155c7f092174e5cb1fd8f2f2;p=haproxy-2.1.git MINOR: ist: Add a case insensitive istmatch function Add a helper function that checks if a string starts with another string while ignoring case. (cherry picked from commit bb4582cf719bcf9facf4e9b459fd3a68a97fffbd) Signed-off-by: Christopher Faulet (cherry picked from commit fce0402a3bebcfae35ce2f7bff00b2e24174d89e) Signed-off-by: Christopher Faulet --- diff --git a/include/common/ist.h b/include/common/ist.h index 0d8b457..3afe74e 100644 --- a/include/common/ist.h +++ b/include/common/ist.h @@ -297,6 +297,26 @@ static inline int istmatch(const struct ist ist1, const struct ist ist2) return 1; } +/* returns non-zero if starts like , 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 starts like on the first * characters (empty strings do match). */