implement startsWith and endsWith.

This commit is contained in:
aaron0x
2016-04-18 01:14:13 +08:00
parent d11b69ca00
commit 43d96a5bcb
3 changed files with 71 additions and 0 deletions

View File

@@ -623,6 +623,22 @@ S cat(const S& delim, const It& begin, const It& end)
}
template <class S>
bool startsWith(const S& str, const S& prefix)
/// Tests whether the string starts with the given prefix.
{
return equal(prefix.begin(), prefix.end(), str.begin());
}
template <class S>
bool endsWith(const S& str, const S& suffix)
/// Tests whether the string ends with the given suffix.
{
return equal(suffix.rbegin(), suffix.rend(), str.rbegin());
}
//
// case-insensitive string equality
//