]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Add i_strccdascmp()
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 18 Feb 2016 13:48:21 +0000 (15:48 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 19 Feb 2016 13:29:58 +0000 (15:29 +0200)
This comparator considers camel case==camel-case==camelCase. This
is to help with HTTP API to make it more flexible.

src/doveadm/doveadm-util.c
src/doveadm/doveadm-util.h

index d32309022ea741743d3e154024f6773efdefbaae..ef44dfbc0a42ed8619e47b517275d3a31dc04cf9 100644 (file)
@@ -13,6 +13,7 @@
 #include <time.h>
 #include <dirent.h>
 #include <sys/stat.h>
+#include <ctype.h>
 
 bool doveadm_verbose = FALSE, doveadm_debug = FALSE, doveadm_server = FALSE;
 static struct module *modules = NULL;
@@ -149,3 +150,21 @@ int doveadm_connect(const char *path)
 {
        return doveadm_connect_with_default_port(path, 0);
 }
+
+int i_strccdascmp(const char *a, const char *b)
+{
+       while(*a && *b) {
+               if ((*a == ' ' || *a == '-') && *a != *b && *b != ' ' && *b != '-') {
+                       if (i_toupper(*(a+1)) == *(b)) a++;
+                       else break;
+               } else if ((*b == ' ' || *b == '-') && *a != *b && *a != ' ' && *a != '-') {
+                       if (*a == i_toupper(*(b+1))) b++;
+                       else break;
+               } else if (!((*a == ' ' || *a == '-') &&
+                            (*b == ' ' || *b == '-')) &&
+                           (*a != *b)) break;
+               a++; b++;
+       }
+       return *a-*b;
+}
+
index e5b5e2d66d743fe541cafd676ed2064c5e88063f..b5bbf2df0d5f251f4b58e11d1e426d4956480a6d 100644 (file)
@@ -18,4 +18,8 @@ void doveadm_load_modules(void);
 void doveadm_unload_modules(void);
 bool doveadm_has_unloaded_plugin(const char *name);
 
+/* Similar to strcmp(), except "camel case" == "camel-case" == "camelCase".
+   Otherwise the comparison is case-sensitive. */
+int i_strccdascmp(const char *a, const char *b) ATTR_PURE;
+
 #endif