Prefer Contains() over find() != npos

This commit is contained in:
J-P Nurmi
2015-08-14 12:46:51 +02:00
parent 6a6fbab342
commit 2417ca68a8
6 changed files with 13 additions and 13 deletions
+2 -2
View File
@@ -495,7 +495,7 @@ bool CModule::AddCommand(const CModCommand& Command)
{
if (Command.GetFunction() == nullptr)
return false;
if (Command.GetCommand().find(' ') != CString::npos)
if (Command.GetCommand().Contains(" "))
return false;
if (FindCommand(Command.GetCommand()) != nullptr)
return false;
@@ -1226,7 +1226,7 @@ bool CModules::FindModPath(const CString& sModule, CString& sModPath,
CString& sDataPath) {
CString sMod = sModule;
CString sDir = sMod;
if (sModule.find(".") == CString::npos)
if (!sModule.Contains("."))
sMod += ".so";
ModDirList dirs = GetModDirs();
+1 -1
View File
@@ -27,7 +27,7 @@ CServer::CServer(const CString& sName, unsigned short uPort, const CString& sPas
CServer::~CServer() {}
bool CServer::IsValidHostName(const CString& sHostName) {
return (!sHostName.empty() && (sHostName.find(' ') == CString::npos));
return (!sHostName.empty() && !sHostName.Contains(" "));
}
const CString& CServer::GetName() const { return m_sName; }
+7 -7
View File
@@ -343,7 +343,7 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) {
CString sMid = CString(sLine.substr(0, iPos2)).Trim_n();
// Make sure we don't have a nested tag
if (sMid.find("<?") == CString::npos) {
if (!sMid.Contains("<?")) {
sLine = sLine.substr(iPos2 +2);
CString sAction = sMid.Token(0);
CString sArgs = sMid.Token(1, true);
@@ -699,26 +699,26 @@ bool CTemplate::ValidExpr(const CString& sExpression) {
bNegate = true;
}
if (sExpr.find("!=") != CString::npos) {
if (sExpr.Contains("!=")) {
sName = sExpr.Token(0, false, "!=").Trim_n();
sValue = sExpr.Token(1, true, "!=", false, "\"", "\"", true).Trim_n();
bNegate = !bNegate;
} else if (sExpr.find("==") != CString::npos) {
} else if (sExpr.Contains("==")) {
sName = sExpr.Token(0, false, "==").Trim_n();
sValue = sExpr.Token(1, true, "==", false, "\"", "\"", true).Trim_n();
} else if (sExpr.find(">=") != CString::npos) {
} else if (sExpr.Contains(">=")) {
sName = sExpr.Token(0, false, ">=").Trim_n();
sValue = sExpr.Token(1, true, ">=", false, "\"", "\"", true).Trim_n();
return (GetValue(sName, true).ToLong() >= sValue.ToLong());
} else if (sExpr.find("<=") != CString::npos) {
} else if (sExpr.Contains("<=")) {
sName = sExpr.Token(0, false, "<=").Trim_n();
sValue = sExpr.Token(1, true, "<=", false, "\"", "\"", true).Trim_n();
return (GetValue(sName, true).ToLong() <= sValue.ToLong());
} else if (sExpr.find(">") != CString::npos) {
} else if (sExpr.Contains(">")) {
sName = sExpr.Token(0, false, ">").Trim_n();
sValue = sExpr.Token(1, true, ">", false, "\"", "\"", true).Trim_n();
return (GetValue(sName, true).ToLong() > sValue.ToLong());
} else if (sExpr.find("<") != CString::npos) {
} else if (sExpr.Contains("<")) {
sName = sExpr.Token(0, false, "<").Trim_n();
sValue = sExpr.Token(1, true, "<", false, "\"", "\"", true).Trim_n();
return (GetValue(sName, true).ToLong() < sValue.ToLong());
+1 -1
View File
@@ -1220,7 +1220,7 @@ bool CUser::DelCTCPReply(const CString& sCTCP) {
}
bool CUser::SetStatusPrefix(const CString& s) {
if ((!s.empty()) && (s.length() < 6) && (s.find(' ') == CString::npos)) {
if ((!s.empty()) && (s.length() < 6) && (!s.Contains(" "))) {
m_sStatusPrefix = (s.empty()) ? "*" : s;
return true;
}
+1 -1
View File
@@ -670,7 +670,7 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS
return PAGE_NOTFOUND;
} else if (sURI.StartsWith("/mods/") || sURI.StartsWith("/modfiles/")) {
// Make sure modules are treated as directories
if (!sURI.EndsWith("/") && sURI.find(".") == CString::npos && sURI.TrimLeft_n("/mods/").TrimLeft_n("/").find("/") == CString::npos) {
if (!sURI.EndsWith("/") && !sURI.Contains(".") && !sURI.TrimLeft_n("/mods/").TrimLeft_n("/").Contains("/")) {
Redirect(sURI + "/");
return PAGE_DONE;
}
+1 -1
View File
@@ -1540,7 +1540,7 @@ bool CZNC::AddListener(const CString& sLine, CString& sError) {
sValue.Replace(":", " ");
}
if (sValue.find(" ") != CString::npos) {
if (sValue.Contains(" ")) {
sBindHost = sValue.Token(0, false, " ");
sPort = sValue.Token(1, true, " ");
} else {