Skip to content

Commit

Permalink
strbuf: use _rtrim and _ltrim in strbuf_trim
Browse files Browse the repository at this point in the history
strbuf_trim() strips whitespace from the end, then the beginning of
a strbuf.  Those operations are duplicated in strbuf_rtrim() and
strbuf_ltrim().

Replace strbuf_trim() implementation with calls to strbuf_rtrim(),
then strbuf_ltrim().

Signed-off-by: Brian Gesiak <modocache@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brian Gesiak authored and Junio C Hamano committed May 6, 2014
1 parent d8779e1 commit 3bb55e8
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)

void strbuf_trim(struct strbuf *sb)
{
char *b = sb->buf;
while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
sb->len--;
while (sb->len > 0 && isspace(*b)) {
b++;
sb->len--;
}
memmove(sb->buf, b, sb->len);
sb->buf[sb->len] = '\0';
strbuf_rtrim(sb);
strbuf_ltrim(sb);
}
void strbuf_rtrim(struct strbuf *sb)
{
Expand Down

0 comments on commit 3bb55e8

Please sign in to comment.