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())
54 if (++wild == mask.end())
62 if ((*wild == *string) || (*wild == '?'))
75 while ((wild != mask.end()) && (*wild == '*'))
78 return wild == mask.end();
81 CoreExport bool match(const std::string &str, const std::string &mask)
83 std::string::const_iterator cp, mp;
84 std::string::const_iterator wild = mask.begin();
85 std::string::const_iterator string = str.begin();
90 while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
92 if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
99 while (string != str.end())
103 if (++wild == mask.end())
111 if ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))
124 while ((wild != mask.end()) && (*wild == '*'))
127 return wild == mask.end();
130 /* Overloaded function that has the option of using cidr */
131 CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match)
133 if (use_cidr_match && MatchCIDR(str, mask, true))
135 return match(str, mask);
138 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match)
140 if (use_cidr_match && MatchCIDR(str, mask, true))
143 return case_sensitive ? csmatch(str, mask) : match(str, mask);
146 CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask)
148 return case_sensitive ? csmatch(str, mask) : match(str, mask);