summaryrefslogtreecommitdiff
path: root/src/wildcard.cpp
diff options
context:
space:
mode:
authorrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-15 15:20:47 +0000
committerrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-15 15:20:47 +0000
commitb10305ef3b568a43541213b3ab102f85695d7d37 (patch)
tree0ba9817f190c9b080b81e3974e89476448299c58 /src/wildcard.cpp
parente1828057c322f6e905bcc55a9b5613853d394081 (diff)
Convert to use new, (drastically) faster matching algorithm, from InspIRCd. This adds Anope::Match(), and marks match_wild() and match_wild_nocase() deprecated.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2059 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/wildcard.cpp')
-rw-r--r--src/wildcard.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
new file mode 100644
index 000000000..f2e9d5e9f
--- /dev/null
+++ b/src/wildcard.cpp
@@ -0,0 +1,81 @@
+#include "services.h"
+
+static bool match_internal(const unsigned char *str, const unsigned char *mask, bool case_sensitive)
+{
+ unsigned char *cp = NULL, *mp = NULL;
+ unsigned char* string = (unsigned char*)str;
+ unsigned char* wild = (unsigned char*)mask;
+
+ while ((*string) && (*wild != '*'))
+ {
+ if (case_sensitive)
+ {
+ if (*wild != *string && *wild != '?')
+ return false;
+ }
+ else
+ {
+ if (tolower(*wild) != tolower(*string) && *wild != '?')
+ return false;
+ }
+
+ wild++;
+ string++;
+ }
+
+ while (*string)
+ {
+ if (*wild == '*')
+ {
+ if (!*++wild)
+ {
+ return 1;
+ }
+
+ mp = wild;
+ cp = string+1;
+ }
+ else
+ {
+ if (case_sensitive)
+ {
+ if (*wild == *string || *wild == '?')
+ {
+ wild++;
+ string++;
+ }
+ else
+ {
+ wild = mp;
+ string = cp++;
+ }
+ }
+ else
+ {
+ if (tolower(*wild) == tolower(*string) || *wild == '?')
+ {
+ wild++;
+ string++;
+ }
+ else
+ {
+ wild = mp;
+ string = cp++;
+ }
+ }
+ }
+
+ }
+
+ while (*wild == '*')
+ {
+ wild++;
+ }
+
+ return !*wild;
+}
+
+CoreExport bool Anope::Match(const std::string &str, const std::string &mask, bool case_sensitive = false)
+{
+ return match_internal(str.c_str(), mask.c_str(), case_sensitive);
+}