mirror of
https://github.com/znc/znc.git
synced 2026-08-10 19:02:51 +02:00
Prefer StartsWith(s) over Left(n) == s
This commit is contained in:
+2
-2
@@ -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);
|
||||
|
||||
@@ -1588,7 +1588,7 @@ void CClient::UserPortCommand(CString& sLine) {
|
||||
if (sPort.empty() || sAddr.empty() || sAccept.empty()) {
|
||||
PutStatus("Usage: AddPort <[+]port> <ipv4|ipv6|all> <web|irc|all> [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);
|
||||
|
||||
|
||||
+3
-3
@@ -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();
|
||||
|
||||
+4
-4
@@ -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...
|
||||
|
||||
+1
-1
@@ -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.");
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ unsigned int CSockManager::GetAnonConnectionCount(const CString &sIP) const {
|
||||
Csock *pSock = *it;
|
||||
// Logged in CClients have "USR::<username>" as their sockname
|
||||
if (pSock->GetType() == Csock::INBOUND && pSock->GetRemoteIP() == sIP
|
||||
&& pSock->GetSockName().Left(5) != "USR::") {
|
||||
&& !pSock->GetSockName().StartsWith("USR::")) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -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<CTemplate*>* 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));
|
||||
}
|
||||
|
||||
+1
-1
@@ -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] == '-') {
|
||||
|
||||
+4
-4
@@ -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/");
|
||||
|
||||
|
||||
+4
-4
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user