From: <kr...@us...> - 2008-09-28 16:59:33
|
Revision: 1224 http://znc.svn.sourceforge.net/znc/?rev=1224&view=rev Author: kroimon Date: 2008-09-28 16:59:28 +0000 (Sun, 28 Sep 2008) Log Message: ----------- Added CString::TrimPrefix() and CString::TrimSuffix() These functions remove prefix/suffix strings if possible. Modified Paths: -------------- trunk/ZNCString.cpp trunk/ZNCString.h Modified: trunk/ZNCString.cpp =================================================================== --- trunk/ZNCString.cpp 2008-09-28 16:55:27 UTC (rev 1223) +++ trunk/ZNCString.cpp 2008-09-28 16:59:28 UTC (rev 1224) @@ -965,6 +965,37 @@ 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); Modified: trunk/ZNCString.h =================================================================== --- trunk/ZNCString.h 2008-09-28 16:55:27 UTC (rev 1223) +++ trunk/ZNCString.h 2008-09-28 16:59:28 UTC (rev 1224) @@ -147,6 +147,11 @@ CString TrimLeft_n(const CString& s = " \t\r\n") const; CString TrimRight_n(const CString& s = " \t\r\n") const; + bool TrimPrefix(const CString& sPrefix); + bool TrimSuffix(const CString& sSuffix); + CString TrimPrefix_n(const CString& sPrefix) const; + CString TrimSuffix_n(const CString& sSuffix) const; + bool LeftChomp(unsigned int uLen = 1); bool RightChomp(unsigned int uLen = 1); CString LeftChomp_n(unsigned int uLen = 1) const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |