Dear All,
I have function that works like this. Here # represnts one word while * is for one alphabet. Can anyone help me changing this code where # is for 0-N words, means it works if at # there is no word between dots, while for * there must be one word, not an alphabet. Any help would be highly appreciated.
main():
std::string aa = "usa.#.* ";
std::string aa = "usa.weather.u" ;
if (wildcmp(aa,rrr))
Console::WriteLine("match found");
else
Console::WriteLine("match not found");
function:
int wildcmp(const char *wild, const char *string) {
// comparing wilcard binding key with routing key
const char *cp = nullptr, *mp = nullptr;
while ((*string) && (*wild != '#'))
{
if ((*wild != *string) && (*wild != '*'))
{
return 0;
}
wild++;
string++;
}
while (*string) {
if (*wild == '#') {
if (!*++wild)
{
return 1;
}
mp = wild;
cp = string+1;
}
else if ((*wild == *string) || (*wild == '*')) {
wild++;
string++;
}
else {
wild = mp;
string = cp++;
}
}
while (*wild == '#') {
wild++;
}
return !*wild;
}