Skip to content

Commit b6b54d6

Browse files
committed
#36 - Implement method CppStringT::lstrip()
Completed.
1 parent fad6641 commit b6b54d6

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cpp-strings/cppstrings.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ namespace pcs // i.e. "pythonic c++ strings"
603603
inline CppStringT& lower() noexcept
604604
{
605605
std::transform(this->begin(), this->end(),
606-
this->begin(),
607-
[](value_type ch) { return this->lower(ch); });
606+
this->begin(),
607+
[](value_type ch) { return this->lower(ch); });
608608
return *this;
609609
}
610610

@@ -619,6 +619,23 @@ namespace pcs // i.e. "pythonic c++ strings"
619619
}
620620

621621

622+
//--- lstrip() ----------------------------------------
623+
/** \brief Return a copy of the string with leading characters removed.
624+
*
625+
* The passed string specifies the set of characters to be removed.
626+
* If omitted, the chars argument defaults to removing whitespace.
627+
* The chars argument is not a prefix; rather, all combinations of
628+
* its values are stripped.
629+
*/
630+
inline CppStringT lstrip(const CppStringT& prefix) const noexcept
631+
{
632+
for (auto it = this->cbegin(); it != this->cend(); ++it)
633+
if (std::none_of(prefix.cbegin(), prefix.cend(), [it](const value_type ch) { *it == ch; }))
634+
return CppStringT(it, this->cend());
635+
return CppStringT();
636+
}
637+
638+
622639
//--- rfind() -----------------------------------------
623640
/** Returns the highest 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.
624641
*
@@ -772,8 +789,8 @@ namespace pcs // i.e. "pythonic c++ strings"
772789
inline CppStringT& upper() noexcept
773790
{
774791
std::transform(this->begin(), this->end(),
775-
this->begin(),
776-
[](value_type ch) { return this->upper(ch); });
792+
this->begin(),
793+
[](value_type ch) { return this->upper(ch); });
777794
return *this;
778795
}
779796

0 commit comments

Comments
 (0)