]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: Add `istshift(struct ist*)`
authorTim Duesterhus <tim@bastelstu.be>
Mon, 5 Apr 2021 15:53:55 +0000 (17:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 17:50:43 +0000 (19:50 +0200)
istshift() returns the first character and advances the ist by 1.

include/import/ist.h

index 3f63ed2dda114a92d3beef94371035675b090db0..6ece7cdf96e981971c61eca2a6b1b4a7774e6e20 100644 (file)
@@ -240,6 +240,21 @@ static inline struct ist istnext(const struct ist ist)
        return ret;
 }
 
+/* Returns the first character of the <ist> and advances the <ist> by 1.
+ * If the <ist> is empty the result is undefined.
+ */
+static inline char istshift(struct ist *ist)
+{
+       if (ist->len) {
+               char c = *ist->ptr;
+               *ist = istnext(*ist);
+
+               return c;
+       }
+
+       return 0;
+}
+
 /* copies the contents from string <ist> to buffer <buf> and adds a trailing
  * zero. The caller must ensure <buf> is large enough.
  */