vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 495a820563e374cc78b4d567fa0862e83bc7822b parent 7f21332809d4d3de32cd4fa897e545bddd571bbd Author: Marc André Tanner <mat@brain-dump.org> Date: Sat, 31 Dec 2016 14:10:11 +0100 buffer: implement buffer_move Diffstat:
| M | buffer.c | | | 7 | +++++++ |
| M | buffer.h | | | 3 | +++ |
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/buffer.c b/buffer.c @@ -168,3 +168,10 @@ const char *buffer_content0(Buffer *buf) { return ""; return buf->data; } + +char *buffer_move(Buffer *buf) { + char *data = buf->data; + buffer_clear(buf); + buf->data = NULL; + return data; +} diff --git a/buffer.h b/buffer.h @@ -57,5 +57,8 @@ size_t buffer_capacity(Buffer*); const char *buffer_content0(Buffer*); /* pointer to buffer data, might be NULL if empty, might not be NUL terminated */ const char *buffer_content(Buffer*); +/* steal underlying buffer data, caller is responsible to free(3) it, + * similar to move semantics in some programming languages */ +char *buffer_move(Buffer*); #endif