vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 400d8a392a5a02fd7c9a0117b7716081858755a0
parent 24a9d34d01c90ea30ff24c2c806d8810929645a7
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 13 Sep 2015 17:35:30 +0200

map: introduce map_contains utility function

Diffstat:
Mmap.c | 5+++++
Mmap.h | 3+++
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/map.c b/map.c @@ -73,6 +73,11 @@ void *map_closest(const Map *map, const char *prefix) return m->v; } +bool map_contains(const Map *map, const char *prefix) +{ + return !map_empty(map_prefix(map, prefix)); +} + bool map_put(Map *map, const char *k, const void *value) { size_t len = strlen(k); diff --git a/map.h b/map.h @@ -12,6 +12,9 @@ void *map_get(const Map*, const char *key); /* Returns the corresponding value if the given prefix is unique. * Otherwise NULL, if no such prefix exists then errno is set to ENOENT. */ void *map_closest(const Map*, const char *prefix); +/* check whether the map contains the given prefix, i.e. whether it can + * be extended to match a key of an element stored in the map. */ +bool map_contains(const Map*, const char *prefix); /* Place a member in the map. This returns false if we run out of memory * (errno = ENOMEM), or if that key already appears in the map (errno = EEXIST). */ bool map_put(Map*, const char *key, const void *value);