From 9582002171b47c49f5de3cb6ae6f7ece788b233b Mon Sep 17 00:00:00 2001 From: w00t Date: Fri, 22 Aug 2008 19:12:18 +0000 Subject: Actually, we did manage to make a faster match than znc, when casemapping is taken into account. Hooray. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10222 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/wildcard.cpp | 79 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'src/wildcard.cpp') diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 4b00e7261..074a91eed 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -18,63 +18,72 @@ #include "inspstring.h" /* - * Wildcard matching, the third (and probably final) iteration! + * Wildcard matching! + * + * Iteration 1) + * Slow, horrible, etc. + * Iteration 2) + * The vastly available 'public domain' one + * Iteration 3) + * ZNC's, thought to be faster than ours, but it turned out that we could do better ;-) + * Iteration 4) + * Largely from work by peavey and myself (w00t) :) * */ -static bool match_internal(const unsigned char *mask, const unsigned char *str, unsigned const char *map) +static bool match_internal(const unsigned char *string, const unsigned char *wild, unsigned const char *map) { - const unsigned char *wild = str; - const unsigned char *string = mask; - const unsigned char *cp = NULL; - const unsigned char *mp = NULL; + const unsigned char* s; if (!map) - map = lowermap; // default to case insensitive search - - while ((*string) && (*wild != '*')) - { - if ((map[*wild] != map[*string]) && (*wild != '?')) - { - return false; - } - - ++wild; - ++string; - } + map = lowermap; while (*string) { if (*wild == '*') { - if (!*++wild) - { + while (*wild && *wild == '*') + wild++; + + if (!*wild) return true; + else if (*wild != '?') + { + s = string; + while (*s) + { + if ((map[*wild] == map[*s])) + { + string = s; + if (*(wild+1) || !*(s+1)) + { + wild++; + break; + } + } + s++; + } } - - mp = wild; - cp = string+1; } - // if mapped char == mapped wild OR wild is ? - else if ((map[*wild] == map[*string]) || (*wild == '?')) + else if ( (map[*wild] != map[*string]) && (*wild != '?') ) { - ++wild; - ++string; + return false; } else - { - wild = mp; - string = cp++; - } + wild++; + + string++; } - while (*wild == '*') - { + while (*wild && *wild == '*') wild++; - } - return (*wild == 0); + return !*wild; } +/******************************************************************** + * Below here is all wrappers around match_internal + ********************************************************************/ + CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map) { return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map); -- cgit v1.2.3