diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt index 3350d97dda2408f92dc44c1e3216facc50257a50..4396be9dda07dfad679f834120b7f1aa2adb16c5 100644 --- a/Documentation/technical/api-strbuf.txt +++ b/Documentation/technical/api-strbuf.txt @@ -121,10 +121,19 @@ Functions * Related to the contents of the buffer +`strbuf_trim`:: + + Strip whitespace from the beginning and end of a string. + Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`. + `strbuf_rtrim`:: Strip whitespace from the end of a string. +`strbuf_ltrim`:: + + Strip whitespace from the beginning of a string. + `strbuf_cmp`:: Compare two buffers. Returns an integer less than, equal to, or greater diff --git a/strbuf.c b/strbuf.c index ee96dcfb816625436582833d812a7156513d5d39..4d31567a1a6a67ae9697816d78da442f87ab5803 100644 --- 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) {