diff --git a/ZNCString.cpp b/ZNCString.cpp index 440ab782..a0a558b7 100644 --- a/ZNCString.cpp +++ b/ZNCString.cpp @@ -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); diff --git a/ZNCString.h b/ZNCString.h index 66baae83..683e0356 100644 --- a/ZNCString.h +++ b/ZNCString.h @@ -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;