diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer.c | 25 | ||||
-rw-r--r-- | src/buffer.h | 1 |
2 files changed, 17 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) diff --git a/src/buffer.h b/src/buffer.h index 1bc1eee..63d6202 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -107,6 +107,7 @@ int strbuf_strchr(const strbuf *buf, int c, int pos); int strbuf_strrchr(const strbuf *buf, int c, int pos); void strbuf_drop(strbuf *buf, int n); void strbuf_truncate(strbuf *buf, int len); +void strbuf_rtrim(strbuf *buf); void strbuf_trim(strbuf *buf); void strbuf_normalize_whitespace(strbuf *s); void strbuf_unescape(strbuf *s); |