Skip to content

Commit

Permalink
Prefer Contains() over find() != npos
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Aug 14, 2015
1 parent 6a6fbab commit 2417ca6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Modules.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Expand Up @@ -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; }
Expand Down
14 changes: 7 additions & 7 deletions src/Template.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/User.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebModules.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/znc.cpp
Expand Up @@ -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 {
Expand Down

0 comments on commit 2417ca6

Please sign in to comment.