Prefer TrimPrefix() over Left() + LeftChomp()

This commit is contained in:
J-P Nurmi
2015-08-14 12:29:42 +02:00
parent 2d5aa8da59
commit 475acd8f00
5 changed files with 7 additions and 16 deletions
+2 -5
View File
@@ -107,9 +107,7 @@ bool CConfig::Parse(CFile& file, CString& sErrorMsg)
sTag.Trim();
sValue.Trim();
if (sTag.Left(1) == "/") {
sTag = sTag.substr(1);
if (sTag.TrimPrefix("/")) {
if (!sValue.empty())
ERROR("Malformated closing tag. Expected \"</" << sTag << ">\".");
if (ConfigStack.empty())
@@ -153,8 +151,7 @@ bool CConfig::Parse(CFile& file, CString& sErrorMsg)
// Only remove the first space, people might want
// leading spaces (e.g. in the MOTD).
if (sValue.Left(1) == " ")
sValue.LeftChomp();
sValue.TrimPrefix(" ");
// We don't have any names with spaces, trim all
// leading/trailing spaces.
+1 -2
View File
@@ -1055,9 +1055,8 @@ bool CIRCNetwork::AddServer(const CString& sName) {
CString sHost = sLine.Token(0);
CString sPort = sLine.Token(1);
if (sPort.Left(1) == "+") {
if (sPort.TrimPrefix("+")) {
bSSL = true;
sPort.LeftChomp();
}
unsigned short uPort = sPort.ToUShort();
+1 -3
View File
@@ -638,9 +638,7 @@ void CIRCSock::ReadLine(const CString& sData) {
}
} else if (sCmd.Equals("MODE")) {
CString sTarget = sRest.Token(0);
CString sModes = sRest.Token(1, true);
if (sModes.Left(1) == ":")
sModes = sModes.substr(1);
CString sModes = sRest.Token(1, true).TrimPrefix_n(":");
CChan* pChan = m_pNetwork->FindChan(sTarget);
if (pChan) {
+2 -4
View File
@@ -695,9 +695,8 @@ bool CTemplate::ValidExpr(const CString& sExpression) {
CString sName;
CString sValue;
if (sExpr.Left(1) == "!") {
if (sExpr.TrimPrefix("!")) {
bNegate = true;
sExpr.LeftChomp();
}
if (sExpr.find("!=") != CString::npos) {
@@ -810,8 +809,7 @@ CString CTemplate::GetValue(const CString& sArgs, bool bFromIf) {
return sRet;
}
} else {
if (sName.Left(1) == "*") {
sName.LeftChomp(1);
if (sName.TrimPrefix("*")) {
MCString::iterator it = find(sName);
sName = (it != end()) ? it->second : "";
}
+1 -2
View File
@@ -1547,8 +1547,7 @@ bool CZNC::AddListener(const CString& sLine, CString& sError) {
sPort = sValue;
}
if (sPort.Left(1) == "+") {
sPort.LeftChomp();
if (sPort.TrimPrefix("+")) {
bSSL = true;
}