Skip to content

Commit

Permalink
use more std::min and remove ostringstream
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Dec 31, 2024
1 parent 92e9737 commit 5490a93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [=] {
Expand Down
6 changes: 3 additions & 3 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(c) << " ";
ss << (static_cast<int>(c) >= 31 && static_cast<int>(c) < 127 ? static_cast<char>(buf[i]) : '.');
ss += (std::isprint(static_cast<int>(c)) ? static_cast<char>(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);
Expand Down

0 comments on commit 5490a93

Please sign in to comment.