aboutsummaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
Diffstat (limited to 'table.c')
-rw-r--r--table.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/table.c b/table.c
index c69bc9c..76c31b5 100644
--- a/table.c
+++ b/table.c
@@ -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;
+}