Skip to content

Commit eab2dab

Browse files
committed
#65 - Implement method rindex_n()
Completed. Fixed a few doc comments; added a missing method signature.
1 parent 2c76cd6 commit eab2dab

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

cpp-strings/cppstrings.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class CppStringT : public std::basic_string<CharT>
244244

245245

246246
//--- index_n() ---------------------------------------
247-
/** Like find_n(sub, start, length), but raises NotFoundException when the substring is not found.
247+
/** Like find_n(sub, start, count), but raises NotFoundException when the substring is not found.
248248
*
249249
* \see index_n(), rindex() and rindex_n().
250250
* \see find(), find_n(), rfind() and rfind_n().
@@ -254,14 +254,14 @@ class CppStringT : public std::basic_string<CharT>
254254
return index(sub, start, start + count - 1);
255255
}
256256

257-
/** Like find_n(sub, start), but raises NotFoundException when the substring is not found.
257+
/** Like find_n(sub, count), but raises NotFoundException when the substring is not found.
258258
*
259259
* \see index_n(), rindex() and rindex_n().
260260
* \see find(), find_n(), rfind() and rfind_n().
261261
*/
262262
inline constexpr size_type index_n(const CppStringT& sub, const size_type count) const
263263
{
264-
return index(sub, 0, count - 1);
264+
return index(sub, 0, count);
265265
}
266266

267267

@@ -393,17 +393,30 @@ class CppStringT : public std::basic_string<CharT>
393393

394394

395395
//--- rfind_n() ---------------------------------------
396-
/** Returns the highest index in the string where substring sub is found within the slice str[start:start+length-1], or -1 (i.e. 'npos') if sub is not found.
396+
/** Returns the highest 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.
397397
*
398398
* Note: this method should be used only if you need to know the position
399399
* of sub. To check if sub is a substring or not, use the method contains_n().
400400
*
401401
* \see find(), find_n() and rfind().
402402
* \see index(), index_n(), rindex() and rindex_n().
403403
*/
404-
inline constexpr size_type rfind_n(const CppStringT& sub, const size_type start, const size_type length) const noexcept
404+
inline constexpr size_type rfind_n(const CppStringT& sub, const size_type start, const size_type count) const noexcept
405405
{
406-
return rfind(sub, start, start + length - 1);
406+
return rfind(sub, start, start + count - 1);
407+
}
408+
409+
/** Returns the highest index in the string where substring sub is found within the slice str[0:count-1], or -1 (i.e. 'npos') if sub is not found.
410+
*
411+
* Note: this method should be used only if you need to know the position
412+
* of sub. To check if sub is a substring or not, use the method contains_n().
413+
*
414+
* \see find(), find_n() and rfind().
415+
* \see index(), index_n(), rindex() and rindex_n().
416+
*/
417+
inline constexpr size_type rfind_n(const CppStringT& sub, const size_type count) const noexcept
418+
{
419+
return rfind(sub, 0, count);
407420
}
408421

409422

@@ -443,6 +456,28 @@ class CppStringT : public std::basic_string<CharT>
443456
}
444457

445458

459+
//--- rindex_n() --------------------------------------
460+
/** Like rfind_n(sub, start, count), but raises NotFoundException when the substring is not found.
461+
*
462+
* \see index_n(), rindex() and rindex_n().
463+
* \see find(), find_n(), rfind() and rfind_n().
464+
*/
465+
inline constexpr size_type rindex_n(const CppStringT& sub, const size_type start, const size_type count) const
466+
{
467+
return rindex(sub, start, start + count - 1);
468+
}
469+
470+
/** Like rfind_n(sub, count), but raises NotFoundException when the substring is not found.
471+
*
472+
* \see index_n(), rindex() and rindex_n().
473+
* \see find(), find_n(), rfind() and rfind_n().
474+
*/
475+
inline constexpr size_type rindex_n(const CppStringT& sub, const size_type count) const
476+
{
477+
return rindex(sub, 0, count);
478+
}
479+
480+
446481
//--- upper () -----------------------------------------
447482
/** \brief In-place replaces all characters of the string with their uppercase conversion. Returns a reference to string.
448483
*

0 commit comments

Comments
 (0)