vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit ac93a434e2501461030a7a6cd4c851e85333b7c5 parent ae64d69fb623a197214f7f2dbfe41821c90cd62c Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 19 Apr 2017 09:33:30 +0200 array: implement array_truncate Diffstat:
| M | array.c | | | 8 | ++++++++ |
| M | array.h | | | 2 | ++ |
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/array.c b/array.c @@ -127,3 +127,11 @@ size_t array_length(Array *arr) { size_t array_capacity(Array *arr) { return arr->count; } + +bool array_truncate(Array *arr, size_t len) { + if (len <= arr->len) { + arr->len = len; + return true; + } + return false; +} diff --git a/array.h b/array.h @@ -56,5 +56,7 @@ bool array_remove(Array*, size_t idx); size_t array_length(Array*); /* return the number of elements which can be stored without enlarging the array */ size_t array_capacity(Array*); +/* remove all elements at index >= length, keep allocated memory */ +bool array_truncate(Array*, size_t length); #endif