Skip to content

Commit

Permalink
Merge branch 'bg/strbuf-trim'
Browse files Browse the repository at this point in the history
* bg/strbuf-trim:
  api-strbuf.txt: add docs for _trim and _ltrim
  strbuf: use _rtrim and _ltrim in strbuf_trim
  • Loading branch information
Junio C Hamano committed Jun 3, 2014
2 parents e1857af + 10f5b03 commit d6850db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Documentation/technical/api-strbuf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 d6850db

Please sign in to comment.