From 2d1d7bd16100eb9d702ef67897b2f62a972d6426 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 12 Mar 2020 17:36:00 +0100 Subject: add hashmap_resolve which handles dot notation --- src/hashmap.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/hashmap.c') diff --git a/src/hashmap.c b/src/hashmap.c index b56b364..9f36a58 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -55,8 +55,32 @@ void *hashmap_get(struct hashmap *hm, char *key) { return NULL; } -void hashmap_remove(char *key) { +void *hashmap_resolve(struct hashmap *hm, char *key) { + char tmp_key[64]; + int i = 0; + int j = 0; + + while (1) { + for (j=0; key[i] != '.' && key[i] != '\0'; i++, j++) { + tmp_key[j] = key[i]; + } + tmp_key[j] = '\0'; + hm = hashmap_get(hm, tmp_key); + + // stop if we read key to end of string + if (key[i] == '\0') { + break; + } + + // otherwise, continue reading keys + i++; + } + return hm; +} + +void hashmap_remove(char *key) { + // TODO: Implement this } void hashmap_free(struct hashmap *hm) { -- cgit v1.2.3