From 5cc84901920b4260fd9ab341c9348da0c283eb9f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 30 Dec 2024 18:10:43 -0800 Subject: [PATCH] use more std::min and remove ostringstream Signed-off-by: Rosen Penev --- src/image.cpp | 8 ++------ src/types.cpp | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 92dc50707e..6c404aa5f9 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -393,13 +393,9 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct return count; // restrict long arrays if (isStringType(type)) { - if (count > 32u) - return 32u; - return count; + return std::min(count, 32u); } - if (count > 5u) - return 5u; - return count; + return std::min(count, 5u); }(); uint32_t pad = isStringType(type) ? 1 : 0; size_t size = [=] { diff --git a/src/types.cpp b/src/types.cpp index 88381372ed..bcb506d5a9 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -459,14 +459,14 @@ void hexdump(std::ostream& os, const byte* buf, size_t len, size_t offset) { size_t i = 0; while (i < len) { os << " " << std::setw(4) << std::setfill('0') << std::hex << i + offset << " "; - std::ostringstream ss; + std::string ss; do { byte c = buf[i]; os << std::setw(2) << std::setfill('0') << std::right << std::hex << static_cast(c) << " "; - ss << (static_cast(c) >= 31 && static_cast(c) < 127 ? static_cast(buf[i]) : '.'); + ss += (std::isprint(static_cast(c)) ? static_cast(buf[i]) : '.'); } while (++i < len && i % 16 != 0); std::string::size_type width = 9 + (((i - 1) % 16 + 1) * 3); - os << (width > pos ? "" : align.substr(width)) << ss.str() << "\n"; + os << (width > pos ? "" : align.substr(width)) << ss << "\n"; } os << std::dec << std::setfill(' '); os.flags(f);