Skip to content

Commit f3cfc00

Browse files
committed
#12 - Implement method CppStringT::count_n()
Completed.
1 parent 9fe08ff commit f3cfc00

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cpp-strings/cppstrings.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ class CppStringT : public std::basic_string<CharT>
150150
return n;
151151
}
152152

153+
154+
//--- count_n() ---------------------------------------
155+
/** \brief Returns the number of non-overlapping occurrences of substring sub in the range [start, start+length-1]. */
156+
inline constexpr size_type count_n(const CppStringT& sub, const size_type start, const size_type length) const noexcept
157+
{
158+
return count(sub, start, start + length - 1);
159+
}
160+
161+
/** \brief Returns the number of non-overlapping occurrences of substring sub in the range [0, length-1]. */
162+
inline constexpr size_type count_n(const CppStringT& sub, const size_type length) const noexcept
163+
{
164+
return count(sub, 0, length - 1);
165+
}
166+
167+
153168
//--- find() ------------------------------------------
154169
/** Returns the lowest index in the string where substring sub is found within the slice str[start:end], or -1 (i.e. 'npos') if sub is not found.
155170
*

0 commit comments

Comments
 (0)