]> git.notmuchmail.org Git - notmuch/commitdiff
util: move strcase_equal and strcase_hash to util
authorJani Nikula <jani@nikula.org>
Thu, 3 Sep 2015 19:40:01 +0000 (22:40 +0300)
committerDavid Bremner <david@tethera.net>
Mon, 7 Sep 2015 12:43:31 +0000 (09:43 -0300)
For future use in both cli and lib.

lib/message-file.c
lib/notmuch-private.h
util/string-util.c
util/string-util.h

index 8ac96e8e06a5dd9a132f241469690c773777fdb4..ee305202fffa63f0e1a1d024c738a1d69a39ebb4 100644 (file)
@@ -37,27 +37,6 @@ struct _notmuch_message_file {
     GMimeMessage *message;
 };
 
     GMimeMessage *message;
 };
 
-static int
-strcase_equal (const void *a, const void *b)
-{
-    return strcasecmp (a, b) == 0;
-}
-
-static 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;
-}
-
 static int
 _notmuch_message_file_destructor (notmuch_message_file_t *message)
 {
 static int
 _notmuch_message_file_destructor (notmuch_message_file_t *message)
 {
index f52b4e4776f956d1854c594574657d84a1d0094a..5dd4770e96190276c3e5077d977cb200aa6f6b82 100644 (file)
@@ -50,6 +50,7 @@ NOTMUCH_BEGIN_DECLS
 
 #include "xutil.h"
 #include "error_util.h"
 
 #include "xutil.h"
 #include "error_util.h"
+#include "string-util.h"
 
 #pragma GCC visibility push(hidden)
 
 
 #pragma GCC visibility push(hidden)
 
index a90501ee3e70198e652599e6da841ffe95db8f85..76c0b9025d0f535243ac7003d5316b22e7e53f17 100644 (file)
@@ -221,3 +221,24 @@ parse_boolean_term (void *ctx, const char *str,
     errno = err;
     return -1;
 }
     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;
+}
index e409cb3d2ab154664a24873cfe50e3ac34a23513..80d24d1c1053035b81144ea51e3ac1934b3d4be7 100644 (file)
@@ -64,6 +64,12 @@ int
 parse_boolean_term (void *ctx, const char *str,
                    char **prefix_out, char **term_out);
 
 parse_boolean_term (void *ctx, const char *str,
                    char **prefix_out, char **term_out);
 
+/* GLib GEqualFunc compatible strcasecmp wrapper */
+int strcase_equal (const void *a, const void *b);
+
+/* GLib GHashFunc compatible case insensitive hash function */
+unsigned int strcase_hash (const void *ptr);
+
 #ifdef __cplusplus
 }
 #endif
 #ifdef __cplusplus
 }
 #endif