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();
38 while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
40 if ((*wild != *string) && (*wild != '?'))
47 while (string != str.end())
51 if (++wild == mask.end())
59 if ((*wild == *string) || (*wild == '?'))
72 while ((wild != mask.end()) && (*wild == '*'))
75 return wild == mask.end();
78 CoreExport bool match(const std::string &str, const std::string &mask)
80 std::string::const_iterator cp, mp;
81 std::string::const_iterator wild = mask.begin();
82 std::string::const_iterator string = str.begin();
84 while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
86 if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
93 while (string != str.end())
97 if (++wild == mask.end())
105 if ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))
118 while ((wild != mask.end()) && (*wild == '*'))
121 return wild == mask.end();
124 /* Overloaded function that has the option of using cidr */
125 CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match)
127 if (use_cidr_match && MatchCIDR(str, mask, true))
129 return match(str, mask);
132 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match)
134 if (use_cidr_match && MatchCIDR(str, mask, true))
137 return case_sensitive ? csmatch(str, mask) : match(str, mask);
140 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask)
142 return case_sensitive ? csmatch(str, mask) : match(str, mask);