summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-11-20 18:36:45 -0500
committerJune McEnroe <june@causal.agency>2018-11-20 18:36:45 -0500
commit0de63b3e4057a92f620b8d1aeef236db560c1753 (patch)
treef7e4bfca50c5e4a7f4bd0ed96b9cf16f76eccf96 /bin
parentAlias ls='ls -p' (diff)
downloadsrc-0de63b3e4057a92f620b8d1aeef236db560c1753.tar.gz
src-0de63b3e4057a92f620b8d1aeef236db560c1753.zip
Add bufferDelete
Diffstat (limited to 'bin')
-rw-r--r--bin/edi/buffer.c16
-rw-r--r--bin/edi/edi.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/bin/edi/buffer.c b/bin/edi/buffer.c
index cefd0a5e..5ece2e51 100644
--- a/bin/edi/buffer.c
+++ b/bin/edi/buffer.c
@@ -66,6 +66,12 @@ void bufferAppend(struct Buffer *buf, wchar_t ch) {
 	buf->slice.len++;
 }
 
+void bufferDelete(struct Buffer *buf) {
+	if (!buf->slice.len) return;
+	buf->slice.len--;
+	buf->len--;
+}
+
 wchar_t *bufferDest(struct Buffer *buf, size_t len) {
 	if (buf->len + len > buf->cap) {
 		while (len > buf->cap) buf->cap *= 2;
@@ -116,6 +122,16 @@ int main() {
 	bufferFree(&buf);
 
 	buf = bufferAlloc(4);
+	bufferInsert(&buf);
+	bufferAppend(&buf, L'A');
+	bufferAppend(&buf, L'B');
+	bufferDelete(&buf);
+	assert(!wcsncmp(L"A", buf.slice.ptr, buf.slice.len));
+	bufferAppend(&buf, L'C');
+	assert(!wcsncmp(L"AC", buf.slice.ptr, buf.slice.len));
+	bufferFree(&buf);
+
+	buf = bufferAlloc(4);
 
 	wchar_t *dest = bufferDest(&buf, 2);
 	dest[0] = L'A';
diff --git a/bin/edi/edi.h b/bin/edi/edi.h
index b2e87e19..3e43e40d 100644
--- a/bin/edi/edi.h
+++ b/bin/edi/edi.h
@@ -44,6 +44,7 @@ struct Buffer bufferAlloc(size_t cap);
 void bufferFree(struct Buffer *buf);
 void bufferInsert(struct Buffer *buf);
 void bufferAppend(struct Buffer *buf, wchar_t ch);
+void bufferDelete(struct Buffer *buf);
 wchar_t *bufferDest(struct Buffer *buf, size_t len);
 
 struct Table {