]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: add an iststop() function
authorJerome Magnin <jmagnin@haproxy.com>
Fri, 21 Feb 2020 09:33:12 +0000 (10:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2020 10:47:25 +0000 (11:47 +0100)
Add a function that finds a character in an ist and returns an
updated ist with the length of the portion of the original string
that doesn't contain the char.

Might be backported to 2.1

include/common/ist.h

index 10c0b6c083d945c295c40be31c21c80f9d4f5c9b..0d8b45721812c174eeed075e3cfad29a535215c6 100644 (file)
@@ -708,4 +708,16 @@ static inline struct ist istist(const struct ist ist, const struct ist pat)
        return ist2(NULL, 0);
 }
 
+/*
+ * looks for the first occurence of <chr> in string <ist> and returns a shorter
+ * ist if char is found.
+ */
+static inline struct ist iststop(const struct ist ist, char chr)
+{
+       size_t len = 0;
+
+       while (len++ < ist.len && ist.ptr[len - 1] != chr)
+               ;
+       return ist2(ist.ptr, len - 1);
+}
 #endif