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
This commit is contained in:
@ -121,10 +121,19 @@ Functions
|
|||||||
|
|
||||||
* Related to the contents of the buffer
|
* 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`::
|
`strbuf_rtrim`::
|
||||||
|
|
||||||
Strip whitespace from the end of a string.
|
Strip whitespace from the end of a string.
|
||||||
|
|
||||||
|
`strbuf_ltrim`::
|
||||||
|
|
||||||
|
Strip whitespace from the beginning of a string.
|
||||||
|
|
||||||
`strbuf_cmp`::
|
`strbuf_cmp`::
|
||||||
|
|
||||||
Compare two buffers. Returns an integer less than, equal to, or greater
|
Compare two buffers. Returns an integer less than, equal to, or greater
|
||||||
|
11
strbuf.c
11
strbuf.c
@ -78,15 +78,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
|
|||||||
|
|
||||||
void strbuf_trim(struct strbuf *sb)
|
void strbuf_trim(struct strbuf *sb)
|
||||||
{
|
{
|
||||||
char *b = sb->buf;
|
strbuf_rtrim(sb);
|
||||||
while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
|
strbuf_ltrim(sb);
|
||||||
sb->len--;
|
|
||||||
while (sb->len > 0 && isspace(*b)) {
|
|
||||||
b++;
|
|
||||||
sb->len--;
|
|
||||||
}
|
|
||||||
memmove(sb->buf, b, sb->len);
|
|
||||||
sb->buf[sb->len] = '\0';
|
|
||||||
}
|
}
|
||||||
void strbuf_rtrim(struct strbuf *sb)
|
void strbuf_rtrim(struct strbuf *sb)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user