Skip to content

Commit

Permalink
strbuf: implement strbuf_strip_suffix
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 30, 2014
1 parent 592ce20 commit 6dda4e6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6dda4e6

Please sign in to comment.