]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: Add `istsplit(struct ist*, char)`
authorTim Duesterhus <tim@bastelstu.be>
Mon, 5 Apr 2021 15:53:56 +0000 (17:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 17:50:43 +0000 (19:50 +0200)
istsplit is a combination of iststop + istadv.

include/import/ist.h

index 6ece7cdf96e981971c61eca2a6b1b4a7774e6e20..daf23d55218bd66e72a4deeccd50d9e0bb03a1dd 100644 (file)
@@ -801,6 +801,20 @@ static inline struct ist istadv(const struct ist ist, const size_t nb)
        return ist2(ist.ptr + nb, ist.len - nb);
 }
 
+/* Splits the given <ist> at the given character. The returned ist is
+ * equivalent to iststop(ist, delim). The passed <ist> will contain the
+ * remainder of the string, not including the delimiter. In other words
+ * it will be advanced by the length of the returned string plus 1.
+ */
+static inline struct ist istsplit(struct ist *ist, char delim)
+{
+       const struct ist result = iststop(*ist, delim);
+
+       *ist = istadv(*ist, result.len + 1);
+
+       return result;
+}
+
 /*
  * compare 2 ists and return non-zero if they are the same
  */