summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c
index d905929..2907159 100644
--- a/src/common.c
+++ b/src/common.c
@@ -571,6 +571,9 @@ struct str_map
size_t alloc; ///< Number of allocated entries
size_t len; ///< Number of entries in the table
void (*free) (void *); ///< Callback to destruct the payload
+
+ /// Callback to compare keys for equivalence
+ int (*key_cmp) (const char *, const char *);
};
// As long as you don't remove the current entry, you can modify the map.
@@ -593,6 +596,7 @@ str_map_init (struct str_map *self)
self->alloc = STR_MAP_MIN_ALLOC;
self->len = 0;
self->free = NULL;
+ self->key_cmp = strcmp;
self->map = xcalloc (self->alloc, sizeof *self->map);
}
@@ -692,7 +696,7 @@ str_map_set (struct str_map *self, const char *key, void *value)
struct str_map_link *iter = self->map[pos];
for (; iter; iter = iter->next)
{
- if (strcmp (key, iter->key))
+ if (self->key_cmp (key, iter->key))
continue;
// Storing the same data doesn't destroy it
@@ -741,7 +745,7 @@ str_map_find (struct str_map *self, const char *key)
{
struct str_map_link *iter = self->map[str_map_pos (self, key)];
for (; iter; iter = iter->next)
- if (!strcmp (key, (char *) iter + sizeof *iter))
+ if (!self->key_cmp (key, (const char *) iter + sizeof *iter))
return iter->data;
return NULL;
}