]> git.notmuchmail.org Git - notmuch/blobdiff - util/string-util.c
util: move strcase_equal and strcase_hash to util
[notmuch] / util / string-util.c
index a90501ee3e70198e652599e6da841ffe95db8f85..76c0b9025d0f535243ac7003d5316b22e7e53f17 100644 (file)
@@ -221,3 +221,24 @@ parse_boolean_term (void *ctx, const char *str,
     errno = err;
     return -1;
 }
+
+int
+strcase_equal (const void *a, const void *b)
+{
+    return strcasecmp (a, b) == 0;
+}
+
+unsigned int
+strcase_hash (const void *ptr)
+{
+    const char *s = ptr;
+
+    /* This is the djb2 hash. */
+    unsigned int hash = 5381;
+    while (s && *s) {
+       hash = ((hash << 5) + hash) + tolower (*s);
+       s++;
+    }
+
+    return hash;
+}