From 7a9ce630efd9ee360904e79dc0ddc1de3182aedc Mon Sep 17 00:00:00 2001 From: uu1101 Date: Sun, 9 Feb 2014 19:45:09 +0100 Subject: [PATCH] Add CString::StartsWith and CString::EndsWith --- include/znc/ZNCString.h | 11 +++++++++++ src/ZNCString.cpp | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/include/znc/ZNCString.h b/include/znc/ZNCString.h index 03fd91bb..bf27f5d7 100644 --- a/include/znc/ZNCString.h +++ b/include/znc/ZNCString.h @@ -478,6 +478,17 @@ public: */ CString TrimSuffix_n(const CString& sSuffix) const; + /** Check whether the string starts with a given prefix. + * @param sPrefix The prefix. + * @return True if the string starts with prefix, false otherwise. + */ + bool StartsWith(const CString& sPrefix) const; + /** Check whether the string ends with a given suffix. + * @param sSuffix The suffix. + * @return True if the string ends with suffix, false otherwise. + */ + bool EndsWith(const CString& sSuffix) const; + /** Remove characters from the beginning of this string. * @param uLen The number of characters to remove. * @return true if this string was modified. diff --git a/src/ZNCString.cpp b/src/ZNCString.cpp index 506a3a24..9287eeca 100644 --- a/src/ZNCString.cpp +++ b/src/ZNCString.cpp @@ -1092,6 +1092,14 @@ bool CString::TrimSuffix(const CString& sSuffix) { } } +bool CString::StartsWith(const CString& sPrefix) const { + return Left(sPrefix.length()).Equals(sPrefix); +} + +bool CString::EndsWith(const CString& sSuffix) const { + return Right(sSuffix.length()).Equals(sSuffix); +} + CString CString::TrimPrefix_n(const CString& sPrefix) const { CString sRet = *this;