Skip to content

Commit ce29faf

Browse files
committed
#174-Test CppStringT::swapcase() with char and wchar_t
Completed. Validated.
1 parent 41860e7 commit ce29faf

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,5 +3843,35 @@ namespace cppstringstests
38433843
Assert::AreEqual(L"", wtext.substr(10, 15).c_str());
38443844
Assert::AreEqual(L"", wtext.substr(21).c_str());
38453845
}
3846+
3847+
TEST_METHOD(swapcase)
3848+
{
3849+
CppString s(255, '\0');
3850+
for (int i : std::views::iota(0, 256))
3851+
s[i] = CppString::value_type(i);
3852+
CppString res{ s.swapcase() };
3853+
for (auto const [s, r] : std::views::zip(s, res)) {
3854+
if (std::islower(s))
3855+
Assert::IsTrue(std::isupper(r));
3856+
else if (std::isupper(s))
3857+
Assert::IsTrue(std::islower(r));
3858+
else
3859+
Assert::AreEqual(s, r);
3860+
}
3861+
3862+
CppWString ws(0xffff, '\0');
3863+
for (int i : std::views::iota(0, 0x1'0000))
3864+
ws[i] = CppWString::value_type(i);
3865+
CppWString wres{ ws.swapcase() };
3866+
for (auto const [ws, wr] : std::views::zip(ws, wres)) {
3867+
if (std::islower(ws))
3868+
Assert::IsTrue(std::isupper(wr));
3869+
else if (std::isupper(ws))
3870+
Assert::IsTrue(std::islower(wr));
3871+
else
3872+
Assert::AreEqual(ws, wr);
3873+
}
3874+
}
3875+
38463876
};
38473877
}

cpp-strings/cppstrings.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,13 +1745,8 @@ namespace pcs // i.e. "pythonic c++ strings"
17451745
*/
17461746
inline CppStringT swapcase() const noexcept
17471747
{
1748-
/*
1749-
CppStringT res(*this);
1750-
std::transform(this->cbegin(), this->cend(), res.begin(), pcs::swap_case);
1751-
return res;
1752-
*/
17531748
CppStringT res;
1754-
std::ranges::copy(std::views::transform(*this, pcs::swap_case), std::back_inserter(res));
1749+
std::ranges::transform(*this, std::back_inserter(res), [](const value_type c) -> value_type { return pcs::swap_case(c); });
17551750
return res;
17561751
}
17571752

0 commit comments

Comments
 (0)