Skip to content

Commit f1f476b

Browse files
committed
#167-Test CppStringT::rstrip() with char and wchar_t
Fixed one bug. Validated.
1 parent 19d9688 commit f1f476b

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,5 +2785,65 @@ namespace cppstringstests
27852785
Assert::AreEqual(L"", wres[7].c_str());
27862786
Assert::AreEqual(L"", wres[8].c_str());
27872787
}
2788+
2789+
TEST_METHOD(rstrip)
2790+
{
2791+
pcs::CppString s(" abcd efg ");
2792+
pcs::CppString sres{ s.rstrip() };
2793+
Assert::AreEqual(" abcd efg", sres.c_str());
2794+
2795+
s = " abcd efg hij"cs;
2796+
sres = s.rstrip();
2797+
Assert::AreEqual(" abcd efg hij", sres.c_str());
2798+
2799+
s = ""cs;
2800+
sres = s.rstrip();
2801+
Assert::AreEqual("", sres.c_str());
2802+
2803+
s = " "cs;
2804+
sres = s.rstrip();
2805+
Assert::AreEqual("", sres.c_str());
2806+
2807+
s = "#124abcd#124efg#124#124#124"cs;
2808+
sres = s.rstrip("#124");
2809+
Assert::AreEqual("#124abcd#124efg", sres.c_str());
2810+
2811+
s = "#124abcd#124efg#124#124hij"cs;
2812+
sres = s.rstrip("#124");
2813+
Assert::AreEqual("#124abcd#124efg#124#124hij", sres.c_str());
2814+
2815+
s = "#124#124#124#124#124";
2816+
sres = s.rstrip("#124");
2817+
Assert::AreEqual("", sres.c_str());
2818+
2819+
pcs::CppWString ws(L" abcd efg ");
2820+
pcs::CppWString wsres{ ws.rstrip() };
2821+
Assert::AreEqual(L" abcd efg", wsres.c_str());
2822+
2823+
ws = L" abcd efg hij"cs;
2824+
wsres = ws.rstrip();
2825+
Assert::AreEqual(L" abcd efg hij", wsres.c_str());
2826+
2827+
ws = L""cs;
2828+
wsres = ws.rstrip();
2829+
Assert::AreEqual(L"", wsres.c_str());
2830+
2831+
ws = L" "cs;
2832+
wsres = ws.rstrip();
2833+
Assert::AreEqual(L"", wsres.c_str());
2834+
2835+
ws = L"#124abcd#124efg#124#124#124"cs;
2836+
wsres = ws.rstrip(L"#124");
2837+
Assert::AreEqual(L"#124abcd#124efg", wsres.c_str());
2838+
2839+
ws = L"#124abcd#124efg#124#124hij"cs;
2840+
wsres = ws.rstrip(L"#124");
2841+
Assert::AreEqual(L"#124abcd#124efg#124#124hij", wsres.c_str());
2842+
2843+
ws = L"#124#124#124#124#124";
2844+
wsres = ws.rstrip(L"#124");
2845+
Assert::AreEqual(L"", wsres.c_str());
2846+
}
2847+
27882848
};
27892849
}

cpp-strings/cppstrings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ namespace pcs // i.e. "pythonic c++ strings"
14761476
{
14771477
for (auto it = this->crbegin(); it != this->crend(); ++it)
14781478
if (std::none_of(suffix.cbegin(), suffix.cend(), [it](const value_type ch) { return *it == ch; }))
1479-
return CppStringT(this->cbegin(), it);
1479+
return CppStringT(this->cbegin(), this->cbegin() + this->size() - (it - this->crbegin()));
14801480
return CppStringT();
14811481
}
14821482

@@ -1485,7 +1485,7 @@ namespace pcs // i.e. "pythonic c++ strings"
14851485
{
14861486
for (auto it = this->crbegin(); it != this->crend(); ++it)
14871487
if (*it != value_type(' '))
1488-
return CppStringT(this->cbegin(), it);
1488+
return CppStringT(this->cbegin(), this->cbegin() + this->size() - (it - this->crbegin()));
14891489
return CppStringT();
14901490
}
14911491

0 commit comments

Comments
 (0)