Skip to content

Commit 6dda4e6

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 592ce20 commit 6dda4e6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

strbuf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ extern void strbuf_rtrim(struct strbuf *);
4747
extern void strbuf_ltrim(struct strbuf *);
4848
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
4949

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+
5059
/*
5160
* Split str (of length slen) at the specified terminator character.
5261
* Return a null-terminated array of pointers to strbuf objects

0 commit comments

Comments
 (0)