Skip to content

Commit 6575060

Browse files
committed
#172-Test CppStringT::strip() with char and wchar_t
Completed. Validated.
1 parent 9005fb0 commit 6575060

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

cpp-strings-tests/cpp-strings-tests.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,15 +2804,15 @@ namespace cppstringstests
28042804
sres = s.rstrip();
28052805
Assert::AreEqual("", sres.c_str());
28062806

2807-
s = "#124abcd#124efg#124#124#124"cs;
2807+
s = "#124abcd#124efg#1241#24#142"cs;
28082808
sres = s.rstrip("#124");
28092809
Assert::AreEqual("#124abcd#124efg", sres.c_str());
28102810

28112811
s = "#124abcd#124efg#124#124hij"cs;
28122812
sres = s.rstrip("#124");
28132813
Assert::AreEqual("#124abcd#124efg#124#124hij", sres.c_str());
28142814

2815-
s = "#124#124#124#124#124";
2815+
s = "#124#142#241124#421#";
28162816
sres = s.rstrip("#124");
28172817
Assert::AreEqual("", sres.c_str());
28182818

@@ -3737,5 +3737,32 @@ namespace cppstringstests
37373737
Assert::IsFalse(wtext.startswith_n({ L"def", L"ghi" }, 0, wlen - 4));
37383738
Assert::IsFalse(wtext.startswith_n({ L"def", L"ghi", L"Abcd" }, 0, wlen - 4));
37393739
}
3740+
3741+
TEST_METHOD(strip)
3742+
{
3743+
CppString text("abcdefedcbaea");
3744+
3745+
Assert::AreEqual("bcdefedcbae", text.strip("a").c_str());
3746+
Assert::AreEqual("cdefedcbae", text.strip("ba").c_str());
3747+
Assert::AreEqual("defedcbae", text.strip("acb").c_str());
3748+
Assert::AreEqual("efedcbae", text.strip("dacb").c_str());
3749+
Assert::AreEqual("f", text.strip("abcde").c_str());
3750+
Assert::AreEqual("bcdefedcb", text.strip("ea").c_str());
3751+
Assert::AreEqual("cdefedc", text.strip("eba").c_str());
3752+
Assert::AreEqual("abcdefedcbaea", text.strip("ghijZ").c_str());
3753+
Assert::AreEqual("abcdefedcbaea", text.strip("ABc").c_str());
3754+
3755+
CppWString wtext(L"abcdefedcbaea");
3756+
3757+
Assert::AreEqual(L"bcdefedcbae", wtext.strip(L"a").c_str());
3758+
Assert::AreEqual(L"cdefedcbae", wtext.strip(L"ba").c_str());
3759+
Assert::AreEqual(L"defedcbae", wtext.strip(L"acb").c_str());
3760+
Assert::AreEqual(L"efedcbae", wtext.strip(L"dacb").c_str());
3761+
Assert::AreEqual(L"f", wtext.strip(L"abcde").c_str());
3762+
Assert::AreEqual(L"bcdefedcb", wtext.strip(L"ea").c_str());
3763+
Assert::AreEqual(L"cdefedc", wtext.strip(L"eba").c_str());
3764+
Assert::AreEqual(L"abcdefedcbaea", wtext.strip(L"ghijZ").c_str());
3765+
Assert::AreEqual(L"abcdefedcbaea", wtext.strip(L"ABc").c_str());
3766+
}
37403767
};
37413768
}

cpp-strings/cppstrings.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,10 @@ namespace pcs // i.e. "pythonic c++ strings"
11221122
* its values are stripped.
11231123
* To remove a prefix, rather call method 'removeprefix()'.
11241124
*/
1125-
inline CppStringT lstrip(const CppStringT& prefix) const noexcept
1125+
inline CppStringT lstrip(const CppStringT& removedchars) const noexcept
11261126
{
11271127
for (auto it = this->cbegin(); it != this->cend(); ++it)
1128-
if (std::none_of(prefix.cbegin(), prefix.cend(), [it](const value_type ch) { return *it == ch; }))
1128+
if (std::none_of(removedchars.cbegin(), removedchars.cend(), [it](const value_type ch) { return *it == ch; }))
11291129
return CppStringT(it, this->cend());
11301130
return CppStringT();
11311131
}
@@ -1473,10 +1473,10 @@ namespace pcs // i.e. "pythonic c++ strings"
14731473
* its values are stripped.
14741474
* To remove a suffix, rather call method 'removesuffix()'.
14751475
*/
1476-
inline CppStringT rstrip(const CppStringT& suffix) const noexcept
1476+
inline CppStringT rstrip(const CppStringT& removedchars) const noexcept
14771477
{
14781478
for (auto it = this->crbegin(); it != this->crend(); ++it)
1479-
if (std::none_of(suffix.cbegin(), suffix.cend(), [it](const value_type ch) { return *it == ch; }))
1479+
if (std::none_of(removedchars.cbegin(), removedchars.cend(), [it](const value_type ch) { return *it == ch; }))
14801480
return CppStringT(this->cbegin(), this->cbegin() + this->size() - (it - this->crbegin()));
14811481
return CppStringT();
14821482
}
@@ -1715,9 +1715,9 @@ namespace pcs // i.e. "pythonic c++ strings"
17151715
* The chars argument is not a prefix; rather, all combinations of
17161716
* its values are stripped.
17171717
*/
1718-
inline CppStringT strip(const CppStringT& prefix) const noexcept
1718+
inline CppStringT strip(const CppStringT& removedchars) const noexcept
17191719
{
1720-
return this->rstrip(prefix).lstrip(prefix);
1720+
return this->rstrip(removedchars).lstrip(removedchars);
17211721
}
17221722

17231723
/** \brief Returns a copy of the string with the leading and trailing whitespaces removed. */

0 commit comments

Comments
 (0)