From ae8d522a998d7cc0f0c876ef202ef4f44e770012 Mon Sep 17 00:00:00 2001 From: prozacx Date: Tue, 10 May 2005 21:06:56 +0000 Subject: [PATCH] Added code for WildCmp() git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@255 726aef4b-f618-498e-8847-2d620e286838 --- String.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/String.cpp b/String.cpp index 3b9278ec..31654981 100644 --- a/String.cpp +++ b/String.cpp @@ -10,7 +10,41 @@ int CString::StrCmp(const CString& s) const { } bool CString::WildCmp(const CString& sWild, const CString& sString) { - return true; // @todo + // Written by Jack Handy - jakkhandy@hotmail.com + const char *wild = sWild.c_str(), *CString = sString.c_str(); + const char *cp = NULL, *mp = NULL; + + while ((*CString) && (*wild != '*')) { + if ((*wild != *CString) && (*wild != '?')) { + return false; + } + + wild++; + CString++; + } + + while (*CString) { + if (*wild == '*') { + if (!*++wild) { + return true; + } + + mp = wild; + cp = CString+1; + } else if ((*wild == *CString) || (*wild == '?')) { + wild++; + CString++; + } else { + wild = mp; + CString = cp++; + } + } + + while (*wild == '*') { + wild++; + } + + return (*wild == 0); } bool CString::WildCmp(const CString& sWild) const {