Skip to content

Commit 9845bab

Browse files
committed
#74 - Implement method CppStringT::startswith_n()
Completed.
1 parent 0b9b7e7 commit 9845bab

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cpp-strings/cppstrings.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,26 @@ namespace pcs // i.e. "pythonic c++ strings"
12851285
}
12861286

12871287

1288+
//--- startswith_n() ----------------------------------
1289+
/** Returns true if the string starts with the specified suffix, otherwise returns false. Test begins at start position and stops after count positions. */
1290+
inline const bool startswith_n(const CppStringT& suffix, const size_type start, const size_type count) const noexcept
1291+
{
1292+
return startswith(std::span{ suffix }, start, start + count - 1);
1293+
}
1294+
1295+
/** Returns true if the string starts with the specified suffix, otherwise returns false. Test begins at position 0 and stops after count positions. */
1296+
inline const bool startswith_n(const CppStringT& suffix, const size_type count) const noexcept
1297+
{
1298+
return startswith(std::span{ suffix }, 0, count - 1);
1299+
}
1300+
1301+
/** Returns true if the string starts with any of the specified suffixes, otherwise returns false. Test begins at start position and stops after count positions. */
1302+
inline const bool startswith_n(const std::span<CppStringT>& suffixes, const size_type start, const size_type count) const noexcept
1303+
{
1304+
return startswith(suffixes, start, start + count - 1);
1305+
}
1306+
1307+
12881308
//--- title() -----------------------------------------
12891309
/** \brief Returns a titlecased copy of the string where words start with an uppercase character and the remaining characters are lowercase. */
12901310
inline CppStringT title() const noexcept

0 commit comments

Comments
 (0)