Skip to content

Commit 11cae64

Browse files
committed
#14 - Implement method CppStringT::endswith_n()
Completed.
1 parent e3d8f11 commit 11cae64

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

cpp-strings/cppstrings.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,25 @@ class CppStringT : public std::basic_string<CharT>
196196

197197

198198
//--- endswith() --------------------------------------
199-
/** Returns true if the string ends with the specified suffix, otherwise return false. Test begins at start position and stops at end position. */
199+
/** Returns true if the string ends with the specified suffix, otherwise returns false. Test begins at start position and stops at end position. */
200200
inline const bool endswith(const CppStringT& suffix, const size_type start, const size_type end) const noexcept
201201
{
202202
return endswith(std::span{ suffix }, start, end);
203203
}
204204

205-
/** Returns true if the string ends with the specified suffix, otherwise return false. Test begins at start position and stops at end of string. */
205+
/** Returns true if the string ends with the specified suffix, otherwise returns false. Test begins at start position and stops at end of string. */
206206
inline const bool endswith(const CppStringT& suffix, const size_type start) const noexcept
207207
{
208208
return endswith(std::span{ suffix }, start, this->size()-1);
209209
}
210210

211-
/** Returns true if the string ends with the specified suffix, otherwise return false. Test runs on the whole string. */
211+
/** Returns true if the string ends with the specified suffix, otherwise returns false. Test runs on the whole string. */
212212
inline const bool endswith(const CppStringT& suffix) const noexcept
213213
{
214214
return this->ends_with(suffix);
215215
}
216216

217-
/** Returns true if the string ends with any of the specified suffixes, otherwise return false. Test begins at start position and stops at end of string. */
217+
/** Returns true if the string ends with any of the specified suffixes, otherwise returns false. Test begins at start position and stops at end of string. */
218218
inline const bool endswith(const std::span<CppStringT>& suffixes, const size_type start, const size_type end) const noexcept
219219
{
220220
if (start > end)
@@ -229,6 +229,26 @@ class CppStringT : public std::basic_string<CharT>
229229
}
230230

231231

232+
//--- endswith_n() ------------------------------------
233+
/** Returns true if the string ends with the specified suffix, otherwise returns false. Test begins at start position and stops after count positions. */
234+
inline const bool endswith_n(const CppStringT& suffix, const size_type start, const size_type count) const noexcept
235+
{
236+
return endswith(std::span{ suffix }, start, start + count - 1);
237+
}
238+
239+
/** Returns true if the string ends with the specified suffix, otherwise returns false. Test begins at position 0 and stops after count positions. */
240+
inline const bool endswith_n(const CppStringT& suffix, const size_type count) const noexcept
241+
{
242+
return endswith(std::span{ suffix }, 0, count - 1);
243+
}
244+
245+
/** Returns true if the string ends with any of the specified suffixes, otherwise returns false. Test begins at start position and stops after count positions. */
246+
inline const bool endswith_n(const std::span<CppStringT>& suffixes, const size_type start, const size_type count) const noexcept
247+
{
248+
return endswith(suffixes, start, start + count - 1);
249+
}
250+
251+
232252
//--- find_n() ----------------------------------------
233253
/** Returns the lowest index in the string where substring sub is found within the slice str[start:start+count-1], or -1 (i.e. 'npos') if sub is not found.
234254
*

0 commit comments

Comments
 (0)