From: Tim Duesterhus Date: Mon, 5 Apr 2021 15:53:55 +0000 (+0200) Subject: MINOR: ist: Add `istshift(struct ist*)` X-Git-Tag: v2.4-dev16~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=90aa8c7f027463f89a5c11c3f18962a896329bb3;p=thirdparty%2Fhaproxy.git MINOR: ist: Add `istshift(struct ist*)` istshift() returns the first character and advances the ist by 1. --- diff --git a/include/import/ist.h b/include/import/ist.h index 3f63ed2dda..6ece7cdf96 100644 --- a/include/import/ist.h +++ b/include/import/ist.h @@ -240,6 +240,21 @@ static inline struct ist istnext(const struct ist ist) return ret; } +/* Returns the first character of the and advances the by 1. + * If the 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 to buffer and adds a trailing * zero. The caller must ensure is large enough. */