diff --git a/src/Client.cpp b/src/Client.cpp index ba3019b3..1e87b191 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -96,7 +96,7 @@ void CClient::ReadLine(const CString& sData) { DEBUG("(" << GetFullName() << ") CLI -> ZNC [" << sLine << "]"); - if (sLine.Left(1) == "@") { + if (sLine.StartsWith("@")) { // TODO support message-tags properly sLine = sLine.Token(1, true); } @@ -110,7 +110,7 @@ void CClient::ReadLine(const CString& sData) { if (bReturn) return; CString sCommand = sLine.Token(0); - if (sCommand.Left(1) == ":") { + if (sCommand.StartsWith(":")) { // Evil client! Sending a nickmask prefix on client's command // is bad, bad, bad, bad, bad, bad, bad, bad, BAD, B A D! sLine = sLine.Token(1, true); diff --git a/src/ClientCommand.cpp b/src/ClientCommand.cpp index f1258357..0852b0d9 100644 --- a/src/ClientCommand.cpp +++ b/src/ClientCommand.cpp @@ -1588,7 +1588,7 @@ void CClient::UserPortCommand(CString& sLine) { if (sPort.empty() || sAddr.empty() || sAccept.empty()) { PutStatus("Usage: AddPort <[+]port> [bindhost [uriprefix]]"); } else { - bool bSSL = (sPort.Left(1).Equals("+")); + bool bSSL = (sPort.StartsWith("+")); const CString sBindHost = sLine.Token(4); const CString sURIPrefix = sLine.Token(5); diff --git a/src/Config.cpp b/src/Config.cpp index 7e7c1906..a77fc9ed 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -85,18 +85,18 @@ bool CConfig::Parse(CFile& file, CString& sErrorMsg) sLine.TrimLeft(); sLine.TrimRight("\r\n"); - if (bCommented || sLine.Left(2) == "/*") { + if (bCommented || sLine.StartsWith("/*")) { /* Does this comment end on the same line again? */ bCommented = (sLine.Right(2) != "*/"); continue; } - if ((sLine.empty()) || (sLine[0] == '#') || (sLine.Left(2) == "//")) { + if ((sLine.empty()) || (sLine.StartsWith("#")) || (sLine.StartsWith("//"))) { continue; } - if ((sLine.Left(1) == "<") && (sLine.Right(1) == ">")) { + if ((sLine.StartsWith("<")) && (sLine.Right(1) == ">")) { sLine.LeftChomp(); sLine.RightChomp(); sLine.Trim(); diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index f0a92a92..3e76ffdb 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -46,7 +46,7 @@ CFile::~CFile() { } void CFile::SetFileName(const CString& sLongName) { - if (sLongName.Left(2) == "~/") { + if (sLongName.StartsWith("~/")) { m_sLongName = CFile::GetHomePath() + sLongName.substr(1); } else m_sLongName = sLongName; @@ -524,7 +524,7 @@ CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString CString sAddDir(sAdd); - if (sAddDir.Left(2) == "~/") { + if (sAddDir.StartsWith("~/")) { sAddDir.LeftChomp(); sAddDir = sHomeDir + sAddDir; } @@ -559,7 +559,7 @@ CString CDir::CheckPathPrefix(const CString& sPath, const CString& sAdd, const C CString sPrefix = sPath.Replace_n("//", "/").TrimRight_n("/") + "/"; CString sAbsolutePath = ChangeDir(sPrefix, sAdd, sHomeDir); - if (sAbsolutePath.Left(sPrefix.length()) != sPrefix) + if (!sAbsolutePath.StartsWith(sPrefix)) return ""; return sAbsolutePath; } @@ -576,7 +576,7 @@ bool CDir::MakeDir(const CString& sPath, mode_t iMode) { } // If this is an absolute path, we need to handle this now! - if (sPath.Left(1) == "/") + if (sPath.StartsWith("/")) sDir = "/"; // For every single subpath, do... diff --git a/src/HTTPSock.cpp b/src/HTTPSock.cpp index 5cb75416..7a48fe00 100644 --- a/src/HTTPSock.cpp +++ b/src/HTTPSock.cpp @@ -385,7 +385,7 @@ bool CHTTPSock::PrintFile(const CString& sFileName, CString sContentType) { } #ifdef HAVE_ZLIB - bool bGzip = m_bAcceptGzip && (sContentType.Left(5).Equals("text/") || sFileName.Right(3).Equals(".js")); + bool bGzip = m_bAcceptGzip && (sContentType.StartsWith("text/") || sFileName.Right(3).Equals(".js")); if (bGzip) { DEBUG("- Sending gzip-compressed."); diff --git a/src/Socket.cpp b/src/Socket.cpp index dd0ceb16..77cd7859 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -69,7 +69,7 @@ unsigned int CSockManager::GetAnonConnectionCount(const CString &sIP) const { Csock *pSock = *it; // Logged in CClients have "USR::" as their sockname if (pSock->GetType() == Csock::INBOUND && pSock->GetRemoteIP() == sIP - && pSock->GetSockName().Left(5) != "USR::") { + && !pSock->GetSockName().StartsWith("USR::")) { ret++; } } diff --git a/src/Template.cpp b/src/Template.cpp index bc9ce186..46965a31 100644 --- a/src/Template.cpp +++ b/src/Template.cpp @@ -108,7 +108,7 @@ void CTemplate::Init() { } CString CTemplate::ExpandFile(const CString& sFilename, bool bFromInc) { - /*if (sFilename.Left(1) == "/" || sFilename.Left(2) == "./") { + /*if (sFilename.StartsWith("/") || sFilename.StartsWith("./")) { return sFilename; }*/ @@ -129,7 +129,7 @@ CString CTemplate::ExpandFile(const CString& sFilename, bool bFromInc) { } if (CFile::Exists(sFilePath)) { - if (sRoot.empty() || sFilePath.Left(sRoot.length()) == sRoot) { + if (sRoot.empty() || sFilePath.StartsWith(sRoot)) { DEBUG(" Found [" + sFilePath + "]"); return sFilePath; } else { @@ -451,15 +451,15 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) { CString sLoopName = sArgs.Token(0); bool bReverse = (sArgs.Token(1).Equals("REVERSE")); - bool bSort = (sArgs.Token(1).Left(4).Equals("SORT")); + bool bSort = (sArgs.Token(1).StartsWith("SORT")); vector* pvLoop = GetLoop(sLoopName); if (bSort && pvLoop != nullptr && pvLoop->size() > 1) { CString sKey; - if(sArgs.Token(1).TrimPrefix_n("SORT").Left(4).Equals("ASC=")) { + if(sArgs.Token(1).TrimPrefix_n("SORT").StartsWith("ASC=")) { sKey = sArgs.Token(1).TrimPrefix_n("SORTASC="); - } else if(sArgs.Token(1).TrimPrefix_n("SORT").Left(5).Equals("DESC=")) { + } else if(sArgs.Token(1).TrimPrefix_n("SORT").StartsWith("DESC=")) { sKey = sArgs.Token(1).TrimPrefix_n("SORTDESC="); bReverse = true; } @@ -766,10 +766,10 @@ CTemplate* CTemplate::GetCurTemplate() { } CString CTemplate::ResolveLiteral(const CString& sString) { - if (sString.Left(2) == "**") { + if (sString.StartsWith("**")) { // Allow string to start with a literal * by using two in a row return sString.substr(1); - } else if (sString.Left(1) == "*") { + } else if (sString.StartsWith("*")) { // If it starts with only one * then treat it as a var and do a lookup return GetValue(sString.substr(1)); } diff --git a/src/Utils.cpp b/src/Utils.cpp index 4cd6b2c1..bd88e18c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -371,7 +371,7 @@ namespace { * ahead/east of GMT.)" */ inline CString FixGMT(CString sTZ) { - if (sTZ.length() >= 4 && sTZ.Left(3) == "GMT") { + if (sTZ.length() >= 4 && sTZ.StartsWith("GMT")) { if (sTZ[3] == '+') { sTZ[3] = '-'; } else if (sTZ[3] == '-') { diff --git a/src/WebModules.cpp b/src/WebModules.cpp index 74e56de6..9c86d67c 100644 --- a/src/WebModules.cpp +++ b/src/WebModules.cpp @@ -649,9 +649,9 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS Redirect("/"); // the login form is here return PAGE_DONE; - } else if (sURI.Left(5) == "/pub/") { + } else if (sURI.StartsWith("/pub/")) { return PrintStaticFile(sURI, sPageRet); - } else if (sURI.Left(11) == "/skinfiles/") { + } else if (sURI.StartsWith("/skinfiles/")) { CString sSkinName = sURI.substr(11); CString::size_type uPathStart = sSkinName.find("/"); if (uPathStart != CString::npos) { @@ -668,7 +668,7 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS } } return PAGE_NOTFOUND; - } else if (sURI.Left(6) == "/mods/" || sURI.Left(10) == "/modfiles/") { + } else if (sURI.StartsWith("/mods/") || sURI.StartsWith("/modfiles/")) { // Make sure modules are treated as directories if (sURI.Right(1) != "/" && sURI.find(".") == CString::npos && sURI.TrimLeft_n("/mods/").TrimLeft_n("/").find("/") == CString::npos) { Redirect(sURI + "/"); @@ -772,7 +772,7 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS AddModLoop("UserModLoop", *pModule); } - if (sURI.Left(10) == "/modfiles/") { + if (sURI.StartsWith("/modfiles/")) { m_Template.AppendPath(GetSkinPath(GetSkinName()) + "/mods/" + m_sModName + "/files/"); m_Template.AppendPath(pModule->GetModDataDir() + "/files/"); diff --git a/src/znc.cpp b/src/znc.cpp index 4d3f092d..62376ad7 100644 --- a/src/znc.cpp +++ b/src/znc.cpp @@ -417,9 +417,9 @@ CString CZNC::ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir) { if (sConfigFile.empty()) { sRetPath = GetConfPath(bAllowMkDir) + "/znc.conf"; } else { - if (sConfigFile.Left(2) == "./" || sConfigFile.Left(3) == "../") { + if (sConfigFile.StartsWith("./") || sConfigFile.StartsWith("../")) { sRetPath = GetCurPath() + "/" + sConfigFile; - } else if (sConfigFile.Left(1) != "/") { + } else if (!sConfigFile.StartsWith("/")) { sRetPath = GetConfPath(bAllowMkDir) + "/" + sConfigFile; } else { sRetPath = sConfigFile; @@ -1762,9 +1762,9 @@ CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users, for (Csock* pSock : m_Manager) { CUser *pUser = nullptr; - if (pSock->GetSockName().Left(5) == "IRC::") { + if (pSock->GetSockName().StartsWith("IRC::")) { pUser = ((CIRCSock *) pSock)->GetNetwork()->GetUser(); - } else if (pSock->GetSockName().Left(5) == "USR::") { + } else if (pSock->GetSockName().StartsWith("USR::")) { pUser = ((CClient*) pSock)->GetUser(); }