Skip to content

Commit

Permalink
Add CString::StartsWith and CString::EndsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
uu1101 committed Feb 15, 2014
1 parent 95cfc22 commit 7a9ce63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/znc/ZNCString.h
Expand Up @@ -478,6 +478,17 @@ class CString : public std::string {
*/ */
CString TrimSuffix_n(const CString& sSuffix) const; 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. /** Remove characters from the beginning of this string.
* @param uLen The number of characters to remove. * @param uLen The number of characters to remove.
* @return true if this string was modified. * @return true if this string was modified.
Expand Down
8 changes: 8 additions & 0 deletions src/ZNCString.cpp
Expand Up @@ -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 CString::TrimPrefix_n(const CString& sPrefix) const {
CString sRet = *this; CString sRet = *this;
Expand Down

0 comments on commit 7a9ce63

Please sign in to comment.