Skip to content

Commit 224de07

Browse files
committed
#17 - Implement method CppStringT::find_n()
Completed.
1 parent f3cfc00 commit 224de07

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cpp-strings/cppstrings.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ class CppStringT : public std::basic_string<CharT>
181181
}
182182

183183

184+
//--- find_n() ----------------------------------------
185+
/** Returns the lowest 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.
186+
*
187+
* Note: this method should be used only if you need to know the position
188+
* of sub. To check if sub is a substring or not, use the method contains_n().
189+
*/
190+
inline constexpr size_type find_n(const CppStringT& sub, const size_type start, const size_type length) const noexcept
191+
{
192+
return find(sub, start, start + length - 1);
193+
}
194+
195+
/** Returns the lowest index in the string where substring sub is found within the slice str[0:length-1], or -1 (i.e. 'npos') if sub is not found.
196+
*
197+
* Note: this method should be used only if you need to know the position
198+
* of sub. To check if sub is a substring or not, use the method contains_n().
199+
*/
200+
inline constexpr size_type find_n(const CppStringT& sub, const size_type length) const noexcept
201+
{
202+
return find(sub, 0, length - 1);
203+
}
204+
205+
184206
//--- is_punctuation() --------------------------------
185207
/** \brief Returns true if the string contains only one character and if this character belongs to the ASCII punctuation set. */
186208
inline const bool is_punctuation() const noexcept

0 commit comments

Comments
 (0)