]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/wildcard.cpp
Add OnParameterMissing to modehandler, called when the mode handler should have a...
[user/henk/code/inspircd.git] / src / wildcard.cpp
index 9846b7d4f4213ee603cc6766cbacaad4b6afdf96..b230ab147daf8245a1e62ad4858e56f6c21d4aa6 100644 (file)
@@ -11,7 +11,7 @@
  * ---------------------------------------------------
  */
 
-/* $Core: libIRCDwildcard */
+/* $Core */
 
 #include "inspircd.h"
 #include "hashcomp.h"
@@ -35,28 +35,36 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask)
        std::string::const_iterator wild = mask.begin();
        std::string::const_iterator string = str.begin();
 
+       if (mask.empty())
+               return false;
+
        while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
        {
                if ((*wild != *string) && (*wild != '?'))
-                       return 0;
+                       return false;
 
                wild++;
                string++;
        }
 
+       if (wild == mask.end() && string != str.end())
+               return false;
+
        while (string != str.end())
        {
-               if (*wild == '*')
+               if (wild != mask.end() && *wild == '*')
                {
                        if (++wild == mask.end())
-                               return 1;
+                               return true;
 
                        mp = wild;
                        cp = string;
-                       cp++;
+
+                       if (cp != str.end())
+                               cp++;
                }
                else
-               if ((*wild == *string) || (*wild == '?'))
+               if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?')))
                {
                        wild++;
                        string++;
@@ -64,7 +72,10 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask)
                else
                {
                        wild = mp;
-                       string = cp++;
+                       if (cp == str.end())
+                               cp = str.end();
+                       else
+                               string = cp++;
                }
 
        }
@@ -81,36 +92,55 @@ CoreExport bool match(const std::string &str, const std::string &mask)
        std::string::const_iterator wild = mask.begin();
        std::string::const_iterator string = str.begin();
 
+       if (mask.empty())
+               return false;
+
        while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
        {
                if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
-                       return 0;
+                       return false;
 
                wild++;
                string++;
+               //printf("Iterate first loop\n");
        }
 
+       if (wild == mask.end() && string != str.end())
+               return false;
+
        while (string != str.end())
        {
-               if (*wild == '*')
+               //printf("outer\n %c", *string);
+               if (wild != mask.end() && *wild == '*')
                {
+
+                       //printf("inner %c\n", *wild);
                        if (++wild == mask.end())
-                               return 1;
+                               return true;
 
                        mp = wild;
                        cp = string;
-                       cp++;
+
+                       if (cp != str.end())
+                               cp++;
+
                }
                else
-               if ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))
+               if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?')))
                {
-                       wild++;
-                       string++;
+                       if (wild != mask.end())
+                               wild++;
+
+                       if (string != str.end())
+                               string++;
                }
                else
                {
                        wild = mp;
-                       string = cp++;
+                       if (cp == str.end())
+                               string = str.end();
+                       else
+                               string = cp++;
                }
 
        }