strbuf: implement strbuf_strip_suffix
You can almost get away with just calling "strip_suffix_mem" on a strbuf's buf and len fields. But we also need to move the NUL-terminator to satisfy strbuf's invariants. Let's provide a convenience wrapper that handles this. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 30, 2014 at 13:01 UTC
6dda4e60f2c3c309de6e3fe1b86a47846a86dabf
1 file changed
+9
strbuf.h
+9
@@ -47,6 +47,15 @@ extern void strbuf_rtrim(struct strbuf *);
47
extern void strbuf_ltrim(struct strbuf *);
48
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
49
50
+static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
51
+{
52
+ if (strip_suffix_mem(sb->buf, &sb->len, suffix)) {
53
+ strbuf_setlen(sb, sb->len);
54
+ return 1;
55
+ } else
56
+ return 0;
57
+}
58
+
59
/*
60
* Split str (of length slen) at the specified terminator character.
61
* Return a null-terminated array of pointers to strbuf objects