Skip to content

Commit 2c76cd6

Browse files
committed
#69 - Fix method rindex()
Completed.
1 parent 14ecbfe commit 2c76cd6

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

cpp-strings/cppstrings.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,7 @@ class CppStringT : public std::basic_string<CharT>
429429
*/
430430
inline constexpr size_type rindex(const CppStringT& sub, const size_type start) const
431431
{
432-
const size_type ret_value = rfind(sub, start);
433-
if (size_type == CppStringT::npos)
434-
throw NotFoundException(std::format("substring \"{}\" not found in string \"{}\"", sub, this->c_str()));
435-
else
436-
return ret_value;
432+
return rindex(sub, start, this->size() - 1);
437433
}
438434

439435
/** Like rfind(sub), but raises NotFoundException when the substring is not found.
@@ -443,11 +439,7 @@ class CppStringT : public std::basic_string<CharT>
443439
*/
444440
inline constexpr size_type rindex(const CppStringT& sub) const
445441
{
446-
const size_type ret_value = rfind(sub);
447-
if (size_type == CppStringT::npos)
448-
throw NotFoundException(std::format("substring \"{}\" not found in string \"{}\"", sub, this->c_str()));
449-
else
450-
return ret_value;
442+
return rindex(sub, 0, this->size() - 1);
451443
}
452444

453445

0 commit comments

Comments
 (0)