vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit b6b61df4f180b7a8c86b4c3c396caf8d6c134d3f parent 8f01a399e14f27b4a92d880dd8f3b841c896587d Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 29 Dec 2016 01:48:13 +0100 map: implement map_prefix_delete Diffstat:
| M | map.c | | | 13 | +++++++++++++ |
| M | map.h | | | 2 | ++ |
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/map.c b/map.c @@ -288,6 +288,19 @@ const Map *map_prefix(const Map *map, const char *prefix) return top; } +bool map_prefix_delete(Map *map, const char *prefix) +{ + bool ret = false; + do { + const char *conflict = NULL; + const Map *conflicts = map_prefix(map, prefix); + if (!map_first(conflicts, &conflict)) + break; + ret = map_delete(map, conflict); + } while (ret); + return ret; +} + static void clear(Map n) { if (!n.v) { diff --git a/map.h b/map.h @@ -31,6 +31,8 @@ void map_iterate(const Map*, bool (*handle)(const char *key, void *value, void * /* Return a submap matching a prefix. This returns a pointer into the * original map, so don't alter the map while using the return value. */ const Map *map_prefix(const Map*, const char *prefix); +/* Delete all entries of the prefix map */ +bool map_prefix_delete(Map*, const char *prefix); /* Test whether the map is empty i.e. contains no elements */ bool map_empty(const Map*); /* Remove every member from the map. The map will be empty after this. */