fix toAscii function

c == 0 was a dead branch because of the way printable ascii was
calculated. Move it up instead.

While at it, replace std::transform with std::replace. Easier to read.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 2 years ago
parent 22a4b71752
commit e1b3dfa278

@ -87,13 +87,11 @@ std::string BmffImage::toAscii(uint32_t n) {
std::string result(p, p + 4); std::string result(p, p + 4);
if (!isBigEndianPlatform()) if (!isBigEndianPlatform())
std::reverse(result.begin(), result.end()); std::reverse(result.begin(), result.end());
std::transform(result.begin(), result.end(), result.begin(), [](char c) { // show 0 as _
if (32 <= c && c < 127) std::replace(result.begin(), result.end(), '\0', '_');
return c; // only allow 7-bit printable ascii // show non 7-bit printable ascii as .
if (c == 0) std::replace_if(
return '_'; // show 0 as _ result.begin(), result.end(), [](char c) { return c < 32 || c > 126; }, '.');
return '.'; // others .
});
return result; return result;
} }

Loading…
Cancel
Save