[PATCH v3 05/17] strbuf: add strbuf_isspace()
- From
Christian Couder <chriscool@tuxfamily.org>
- Date
- Jan 26, 2014, 16:59 UTC
- Message-ID
- <20140126170011.24291.54182.chriscool@tuxfamily.org>
- In-Reply-To
- <20140126165018.24291.47716.chriscool@tuxfamily.org>
This helper function checks if a strbuf contains only space chars or not.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org> --- strbuf.c | 7 +++++++ strbuf.h | 1 + 2 files changed, 8 insertions(+)
diff --git a/strbuf.c b/strbuf.c index 83caf4a..2124bb8 100644 --- a/strbuf.c +++ b/strbuf.c @@ -124,6 +124,13 @@ void strbuf_ltrim(struct strbuf *sb) sb->buf[sb->len] = '\0'; } +int strbuf_isspace(struct strbuf *sb) +{ + char *b; + for (b = sb->buf; *b && isspace(*b); b++); + return !*b; +} + struct strbuf **strbuf_split_buf(const char *str, size_t slen, int terminator, int max) { diff --git a/strbuf.h b/strbuf.h index 73e80ce..02bff3a 100644 --- a/strbuf.h +++ b/strbuf.h @@ -42,6 +42,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) { extern void strbuf_trim(struct strbuf *); extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); +extern int strbuf_isspace(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); /*
-- 1.8.5.2.201.gacc5987