Skip to content

Commit 43f92f7

Browse files
committed
#151 - Test CppStringT::is_words_sep() with char and wchar_t
Tested.
1 parent 474642e commit 43f92f7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,5 +696,24 @@ namespace cppstringstests
696696
}
697697
}
698698

699+
TEST_METHOD(is_words_sep)
700+
{
701+
Assert::IsFalse(CppString().is_words_sep());
702+
for (int c = 32; c <= 255; ++c) {
703+
const char ch{ char(c) };
704+
pcs::CppString s(5, ch);
705+
Assert::AreEqual(pcs::is_space(ch) || pcs::is_punctuation(ch), s.is_words_sep());
706+
}
707+
708+
Assert::IsFalse(CppWString().is_words_sep());
709+
for (int c = 0; c <= 0xffff; ++c) {
710+
const wchar_t wch{ wchar_t(c) };
711+
pcs::CppWString ws(5, wch);
712+
Assert::AreEqual(pcs::is_space(wch) || pcs::is_punctuation(wch), ws.is_words_sep());
713+
}
714+
}
715+
716+
717+
699718
};
700719
}

cpp-strings/cppstrings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,8 @@ namespace pcs // i.e. "pythonic c++ strings"
10051005
/** \brief Returns true if there are only whitespace and punctuation characters in the string and there is at least one character, or false otherwise. */
10061006
inline const bool is_words_sep() const noexcept
10071007
{
1008-
return isspace() || ispunctuation();
1008+
return !this->empty() && std::all_of(this->cbegin(), this->cend(),
1009+
[](const value_type ch){ return pcs::is_space(ch) || pcs::is_punctuation(ch); });
10091010
}
10101011

10111012

0 commit comments

Comments
 (0)