From 0823b27f37b27d345a741c984ea7dab1c34feda2 Mon Sep 17 00:00:00 2001 From: prozacx Date: Sun, 8 May 2005 07:51:46 +0000 Subject: [PATCH] Moved CUtils::wildcmp() into CString class git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@251 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.h | 2 +- IRCSock.cpp | 6 +++--- User.cpp | 2 +- UserSock.cpp | 6 +++--- Utils.cpp | 38 -------------------------------------- Utils.h | 2 -- modules/watch.cpp | 4 ++-- 7 files changed, 10 insertions(+), 50 deletions(-) diff --git a/FileUtils.h b/FileUtils.h index 365ddcdd..fcfe6a04 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -207,7 +207,7 @@ public: if ((strcmp(de->d_name, ".") == 0) || (strcmp(de->d_name, "..") == 0)) { continue; } - if ((!sWildcard.empty()) && (!CUtils::wildcmp(sWildcard.c_str(), de->d_name))) { + if ((!sWildcard.empty()) && (!CString(de->d_name).WildCmp(sWildcard))) { continue; } diff --git a/IRCSock.cpp b/IRCSock.cpp index 3c0d1957..6c7b1ccb 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -59,7 +59,7 @@ void CIRCSock::ReadLine(const CString& sData) { if (strncasecmp(sLine.c_str(), "PING ", 5) == 0) { PutServ("PONG " + sLine.substr(5)); - } else if (CUtils::wildcmp(":* * *", sLine.c_str())) { //"^:(\\S+) (\\d\\d\\d) (.*?) (.*)$", vCap)) { + } else if (sLine.WildCmp(":* * *")) { //"^:(\\S+) (\\d\\d\\d) (.*?) (.*)$", vCap)) { CString sCmd = sLine.Token(1); if ((sCmd.length() == 3) && (isdigit(sCmd[0])) && (isdigit(sCmd[1])) && (isdigit(sCmd[2]))) { @@ -503,7 +503,7 @@ void CIRCSock::ReadLine(const CString& sData) { CString sMsg = sRest.Token(1, true); sMsg.LeftChomp(); - if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { + if (sMsg.WildCmp("\001*\001")) { sMsg.LeftChomp(); sMsg.RightChomp(); @@ -552,7 +552,7 @@ void CIRCSock::ReadLine(const CString& sData) { sMsg.LeftChomp(); } - if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { + if (sMsg.WildCmp("\001*\001")) { sMsg.LeftChomp(); sMsg.RightChomp(); diff --git a/User.cpp b/User.cpp index fa3db887..22c5839b 100644 --- a/User.cpp +++ b/User.cpp @@ -62,7 +62,7 @@ bool CUser::IsHostAllowed(const CString& sHostMask) { } for (set::iterator a = m_ssAllowedHosts.begin(); a != m_ssAllowedHosts.end(); a++) { - if (CUtils::wildcmp(*a, sHostMask)) { + if (sHostMask.WildCmp(*a)) { return true; } } diff --git a/UserSock.cpp b/UserSock.cpp index f29c3286..2fa9b360 100644 --- a/UserSock.cpp +++ b/UserSock.cpp @@ -147,7 +147,7 @@ void CUserSock::ReadLine(const CString& sData) { return; } - if (CUtils::wildcmp("DCC * (*)", sMsg.c_str())) { + if (sMsg.WildCmp("DCC * (*)")) { sMsg = "DCC " + sLine.Token(3) + " (" + ((m_pIRCSock) ? m_pIRCSock->GetLocalIP() : GetLocalIP()) + ")"; } @@ -158,7 +158,7 @@ void CUserSock::ReadLine(const CString& sData) { } #ifdef _MODULES - if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { + if (sMsg.WildCmp("\001*\001")) { CString sCTCP = sMsg; sCTCP.LeftChomp(); sCTCP.RightChomp(); @@ -185,7 +185,7 @@ void CUserSock::ReadLine(const CString& sData) { sMsg.LeftChomp(); } - if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { + if (sMsg.WildCmp("\001*\001")) { CString sCTCP = sMsg; sCTCP.LeftChomp(); sCTCP.RightChomp(); diff --git a/Utils.cpp b/Utils.cpp index da0f0925..903489dc 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -370,44 +370,6 @@ void CUtils::PrintStatus(bool bSuccess, const CString& sMessage) { } } -bool CUtils::wildcmp(const CString& sWild, const CString& sString) { - // 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); -} - CTable::CTable() {} CTable::~CTable() { for (unsigned int a = 0; a < size(); a++) { diff --git a/Utils.h b/Utils.h index ae766843..8e98ed9a 100644 --- a/Utils.h +++ b/Utils.h @@ -42,8 +42,6 @@ public: static bool GetBoolInput(const CString& sPrompt, bool *pbDefault = NULL); static bool GetNumInput(const CString& sPrompt, unsigned int& uRet, unsigned int uMin = 0, unsigned int uMax = ~0, unsigned int uDefault = ~0); - static bool wildcmp(const CString& sWild, const CString& sString); - static unsigned long long GetMillTime() { struct timeval tv; unsigned long long iTime = 0; diff --git a/modules/watch.cpp b/modules/watch.cpp index 82130112..6d52c783 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -67,7 +67,7 @@ public: for (unsigned int a = 0; a < m_vsSources.size(); a++) { const CWatchSource& WatchSource = m_vsSources[a]; - if (CUtils::wildcmp(Lower(WatchSource.GetSource()), Lower(sSource))) { + if (sSource.AsLower().WildCmp(Lower(WatchSource.GetSource()))) { if (WatchSource.IsNegated()) { return false; } else { @@ -77,7 +77,7 @@ public: } } - return (bGoodSource && CUtils::wildcmp(Lower(m_sHostMask), Lower(Nick.GetHostMask())) && CUtils::wildcmp(Lower(m_sPattern), Lower(sText))); + return (bGoodSource && Nick.GetHostMask().AsLower().WildCmp(Lower(m_sHostMask))) && sText.AsLower().WildCmp(Lower(m_sPattern)); } bool operator ==(const CWatchEntry& WatchEntry) {