1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 11:56:38 +02:00
Files
anope/src/wildcard.cpp
T
rburchell f92bf30f15 Fix compile error.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2060 5417fbe8-f217-4b02-8779-1006273d7864
2009-02-15 15:21:06 +00:00

82 lines
1.3 KiB
C++

#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)
{
return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), case_sensitive);
}