Skip to content

Commit d6850db

Browse files
committed
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
2 parents e1857af + 10f5b03 commit d6850db

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Documentation/technical/api-strbuf.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,19 @@ Functions
121121

122122
* Related to the contents of the buffer
123123

124+
`strbuf_trim`::
125+
126+
Strip whitespace from the beginning and end of a string.
127+
Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`.
128+
124129
`strbuf_rtrim`::
125130

126131
Strip whitespace from the end of a string.
127132

133+
`strbuf_ltrim`::
134+
135+
Strip whitespace from the beginning of a string.
136+
128137
`strbuf_cmp`::
129138

130139
Compare two buffers. Returns an integer less than, equal to, or greater

strbuf.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
7878

7979
void strbuf_trim(struct strbuf *sb)
8080
{
81-
char *b = sb->buf;
82-
while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
83-
sb->len--;
84-
while (sb->len > 0 && isspace(*b)) {
85-
b++;
86-
sb->len--;
87-
}
88-
memmove(sb->buf, b, sb->len);
89-
sb->buf[sb->len] = '\0';
81+
strbuf_rtrim(sb);
82+
strbuf_ltrim(sb);
9083
}
9184
void strbuf_rtrim(struct strbuf *sb)
9285
{

0 commit comments

Comments
 (0)