strbuf: use _rtrim and _ltrim in strbuf_trim
authorBrian Gesiak <modocache@gmail.com>
Wed, 30 Apr 2014 08:58:06 +0000 (17:58 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 May 2014 22:33:39 +0000 (15:33 -0700)
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>
strbuf.c
index ee96dcfb816625436582833d812a7156513d5d39..4d31567a1a6a67ae9697816d78da442f87ab5803 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -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)
 {