1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDwildcard */
18 #include "inspstring.h"
20 using irc::sockets::MatchCIDR;
22 /* Rewritten to operate on more effective C++ std::string types
23 * rather than char* to avoid data copies.
27 CoreExport bool csmatch(const std::string &str, const std::string &mask)
29 std::string::const_iterator cp, mp;
31 //unsigned char *cp = NULL, *mp = NULL;
32 //unsigned char* string = (unsigned char*)str;
33 //unsigned char* wild = (unsigned char*)mask;
35 std::string::const_iterator wild = mask.begin();
36 std::string::const_iterator string = str.begin();
41 while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
43 if ((*wild != *string) && (*wild != '?'))
50 while (string != str.end())
52 if (wild != mask.end() && *wild == '*')
54 if (++wild == mask.end())
64 if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?')))
80 while ((wild != mask.end()) && (*wild == '*'))
83 return wild == mask.end();
86 CoreExport bool match(const std::string &str, const std::string &mask)
88 std::string::const_iterator cp, mp;
89 std::string::const_iterator wild = mask.begin();
90 std::string::const_iterator string = str.begin();
95 while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
97 if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
104 while (string != str.end())
106 if (wild != mask.end() && *wild == '*')
108 if (++wild == mask.end())
119 if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?')))
135 while ((wild != mask.end()) && (*wild == '*'))
138 return wild == mask.end();
141 /* Overloaded function that has the option of using cidr */
142 CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match)
144 if (use_cidr_match && MatchCIDR(str, mask, true))
146 return match(str, mask);
149 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match)
151 if (use_cidr_match && MatchCIDR(str, mask, true))
154 return case_sensitive ? csmatch(str, mask) : match(str, mask);
157 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask)
159 return case_sensitive ? csmatch(str, mask) : match(str, mask);