]> jfr.im git - irc/rizon/znc.git/commitdiff
Added CString::TrimPrefix() and CString::TrimSuffix()
authorkroimon <redacted>
Sun, 28 Sep 2008 16:59:28 +0000 (16:59 +0000)
committerkroimon <redacted>
Sun, 28 Sep 2008 16:59:28 +0000 (16:59 +0000)
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

ZNCString.cpp
ZNCString.h

index 440ab782adcec5a58c96979396941fc4288654b8..a0a558b702eb7d144ef568d09fecc077b3043df2 100644 (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);
index 66baae83ab24787806c8b5e92760911bc5e8a8cf..683e0356e42d48df6963087194d6f8cafdf39e2a 100644 (file)
@@ -147,6 +147,11 @@ public:
        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;