diff options
Diffstat (limited to 'table.c')
-rw-r--r-- | table.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -179,3 +179,22 @@ void clear_table(struct table *tbl) { size_t get_table_offset(struct table tbl, struct string name, char *exists) { return search(tbl, name, exists); } + +void * get_table_prefix(struct table tbl, struct string name) { + char exists; + size_t index = search(tbl, name, &exists); + if (exists) + return tbl.array[index].ptr; + + if (index == 0) + return 0; + + size_t len = tbl.array[index - 1].name.len; + if (len > name.len) + return 0; + + if (memcmp(tbl.array[index - 1].name.data, name.data, len) != 0) + return 0; + + return tbl.array[index - 1].ptr; +} |