diff options
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c index 1cdcae8..a5139fa 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -291,19 +291,11 @@ void strbuf_drop(strbuf *buf, int n) } } -void strbuf_trim(strbuf *buf) +void strbuf_rtrim(strbuf *buf) { - int i = 0; - if (!buf->size) return; - while (i < buf->size && isspace(buf->ptr[i])) - i++; - - strbuf_drop(buf, i); - - /* rtrim */ while (buf->size > 0) { if (!isspace(buf->ptr[buf->size - 1])) break; @@ -314,6 +306,21 @@ void strbuf_trim(strbuf *buf) buf->ptr[buf->size] = '\0'; } +void strbuf_trim(strbuf *buf) +{ + int i = 0; + + if (!buf->size) + return; + + while (i < buf->size && isspace(buf->ptr[i])) + i++; + + strbuf_drop(buf, i); + + strbuf_rtrim(buf); +} + // Destructively modify string, collapsing consecutive // space and newline characters into a single space. void strbuf_normalize_whitespace(strbuf *s) |