Added CString::TrimPrefix() and CString::TrimSuffix()

These functions remove prefix/suffix strings if possible.

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1224 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
kroimon
2008-09-28 16:59:28 +00:00
parent 038961359e
commit e693acaa66
2 changed files with 36 additions and 0 deletions

View File

@@ -965,6 +965,37 @@ CString CString::TrimRight_n(const CString& s) const {
return sRet;
}
bool CString::TrimPrefix(const CString& sPrefix) {
if (CaseCmp(sPrefix, sPrefix.length()) == 0) {
LeftChomp(sPrefix.length());
return true;
} else {
return false;
}
}
bool CString::TrimSuffix(const CString& sSuffix) {
if (Right(sSuffix.length()).CaseCmp(sSuffix) == 0) {
RightChomp(sSuffix.length());
return true;
} else {
return false;
}
}
CString CString::TrimPrefix_n(const CString& sPrefix) const {
CString sRet = *this;
sRet.TrimPrefix(sPrefix);
return sRet;
}
CString CString::TrimSuffix_n(const CString& sSuffix) const {
CString sRet = *this;
sRet.TrimSuffix(sSuffix);
return sRet;
}
CString CString::LeftChomp_n(unsigned int uLen) const {
CString sRet = *this;
sRet.LeftChomp(uLen);