mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-04-19 21:02:17 +03:00
Fixed id ostream operator to print human readable ids
This commit is contained in:
parent
6d0b37daaf
commit
bccb9997f2
@ -54,9 +54,12 @@ std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::id& id)
|
||||
{
|
||||
const char* ptr(static_cast<const char*>(id.data()));
|
||||
size_t size(id.size());
|
||||
if (static_cast<size_t>(std::count_if(ptr, ptr + size, ::isalnum)) == size)
|
||||
if (static_cast<size_t>(
|
||||
std::count_if(ptr, ptr + size,
|
||||
[](char c) { return (::isalnum(c) || c == '\0'); }))
|
||||
== size)
|
||||
{
|
||||
return (os << std::string(ptr, size));
|
||||
return (os << std::string(ptr, ::strnlen(ptr, size)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -37,6 +37,15 @@ BOOST_AUTO_TEST_CASE(id_test_uuid)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(id_test_string)
|
||||
{
|
||||
std::string id_str("node1");
|
||||
wsrep::id id(id_str);
|
||||
std::ostringstream os;
|
||||
os << id;
|
||||
BOOST_REQUIRE(id_str == os.str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(id_test_string_max)
|
||||
{
|
||||
std::string id_str("1234567890123456");
|
||||
wsrep::id id(id_str);
|
||||
|
Loading…
x
Reference in New Issue
Block a user