Mercurial > dovecot > core-2.2
changeset 19765:e2f06973080f
doveadm: Add i_strccdascmp()
This comparator considers camel case==camel-case==camelCase. This
is to help with HTTP API to make it more flexible.
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Thu, 18 Feb 2016 15:48:21 +0200 |
parents | 68b734d7be0d |
children | f2d7c8fb2a94 |
files | src/doveadm/doveadm-util.c src/doveadm/doveadm-util.h |
diffstat | 2 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-util.c Fri Feb 19 14:08:40 2016 +0200 +++ b/src/doveadm/doveadm-util.c Thu Feb 18 15:48:21 2016 +0200 @@ -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 @@ { 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; +} +
--- a/src/doveadm/doveadm-util.h Fri Feb 19 14:08:40 2016 +0200 +++ b/src/doveadm/doveadm-util.h Thu Feb 18 15:48:21 2016 +0200 @@ -18,4 +18,8 @@ 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