summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-06-03 12:06:46 -0700
committerJunio C Hamano <gitster@pobox.com>2014-06-03 12:06:46 -0700
commitd6850db3c27e4d6c591f046d998f5dc7cc883047 (patch)
tree090fc12aa22446c8c16673dc8b55018e001f7823
parente1857af92389f47e9365b4f8a718831fa6f96db0 (diff)
parent10f5b034b6aaff706c4776b3cc0ee993c33e8f43 (diff)
downloadgit-d6850db3c27e4d6c591f046d998f5dc7cc883047.tar.gz
Merge branch 'bg/strbuf-trim'
* bg/strbuf-trim: api-strbuf.txt: add docs for _trim and _ltrim strbuf: use _rtrim and _ltrim in strbuf_trim
-rw-r--r--Documentation/technical/api-strbuf.txt9
-rw-r--r--strbuf.c11
2 files changed, 11 insertions, 9 deletions
diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt
index 3350d97dda..4396be9dda 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 ee96dcfb81..4d31567a1a 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)
{