summaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-30 17:01:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-30 20:43:32 (GMT)
commit6dda4e60f2c3c309de6e3fe1b86a47846a86dabf (patch)
tree1e1ba2572a16b536e1f7f65130d907b9615b9258 /strbuf.h
parent592ce20820ac36dd868dfd1e61b1aeb3cd3f902a (diff)
downloadgit-6dda4e60f2c3c309de6e3fe1b86a47846a86dabf.zip
git-6dda4e60f2c3c309de6e3fe1b86a47846a86dabf.tar.gz
git-6dda4e60f2c3c309de6e3fe1b86a47846a86dabf.tar.bz2
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>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index 39c14cf..1d768c1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -47,6 +47,15 @@ extern void strbuf_rtrim(struct strbuf *);
extern void strbuf_ltrim(struct strbuf *);
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
+static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
+{
+ if (strip_suffix_mem(sb->buf, &sb->len, suffix)) {
+ strbuf_setlen(sb, sb->len);
+ return 1;
+ } else
+ return 0;
+}
+
/*
* Split str (of length slen) at the specified terminator character.
* Return a null-terminated array of pointers to strbuf objects