From e1b3dfa2788bad83ce941aafcff286d3b2e4b55e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 14 Jul 2023 14:56:17 -0700 Subject: [PATCH] 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 --- src/bmffimage.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index 8f8b0e4b..78b0f20c 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -87,13 +87,11 @@ std::string BmffImage::toAscii(uint32_t n) { std::string result(p, p + 4); if (!isBigEndianPlatform()) std::reverse(result.begin(), result.end()); - std::transform(result.begin(), result.end(), result.begin(), [](char c) { - if (32 <= c && c < 127) - return c; // only allow 7-bit printable ascii - if (c == 0) - return '_'; // show 0 as _ - return '.'; // others . - }); + // show 0 as _ + std::replace(result.begin(), result.end(), '\0', '_'); + // show non 7-bit printable ascii as . + std::replace_if( + result.begin(), result.end(), [](char c) { return c < 32 || c > 126; }, '.'); return result; }