aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-06 20:57:36 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-06 20:57:36 -0800
commit3317e5039f5c940225dffa5c735507e897c230b8 (patch)
treeae962e0c27a591dfea7c5cf51d771043ac892afe /src
parente76ccb29825b42c69c308ab3119c3b5ef68b8027 (diff)
buffer: added strbuf_rtrim function.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c25
-rw-r--r--src/buffer.h1
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);