diff --git a/samples/conntest.cpp b/samples/conntest.cpp index fd2943bf86..80ef6e3639 100644 --- a/samples/conntest.cpp +++ b/samples/conntest.cpp @@ -37,7 +37,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) { // get the timeout value std::string timeoutStr = Exiv2::getEnv(Exiv2::envTIMEOUT); - long timeout = atol(timeoutStr.c_str()); + long timeout = std::stol(timeoutStr); if (timeout == 0) { throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); } diff --git a/src/basicio.cpp b/src/basicio.cpp index 5bbea74579..dd9b188e17 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -1422,7 +1422,7 @@ int64_t HttpIo::HttpImpl::getFileLength() { } auto lengthIter = response.find("Content-Length"); - return (lengthIter == response.end()) ? -1 : atol((lengthIter->second).c_str()); + return (lengthIter == response.end()) ? -1 : std::stoll(lengthIter->second); } void HttpIo::HttpImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::string& response) { @@ -1560,7 +1560,7 @@ CurlIo::CurlImpl::CurlImpl(const std::string& url, size_t blockSize) : Impl(url, } std::string timeout = getEnv(envTIMEOUT); - timeout_ = atol(timeout.c_str()); + timeout_ = std::stol(timeout); if (timeout_ == 0) { throw Error(ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); } diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index aebbb07a02..0ea190119f 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -544,9 +544,11 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) { auto dir = crwDirs.top(); crwDirs.pop(); // Find the directory - auto it = std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tag() == dir.dir; }); - if (it != components_.end()) - cc_ = *it; + for (const auto& c : components_) + if (c->tag() == dir.dir) { + cc_ = c; + break; + } if (!cc_) { // Directory doesn't exist yet, add it m_ = std::make_unique(dir.dir, dir.parent); @@ -557,10 +559,11 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) { cc_ = cc_->add(crwDirs, crwTagId); } else { // Find the tag - auto it = - std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tagId() == crwTagId; }); - if (it != components_.end()) - cc_ = *it; + for (const auto& c : components_) + if (c->tagId() == crwTagId) { + cc_ = c; + break; + } if (!cc_) { // Tag doesn't exist yet, add it m_ = std::make_unique(crwTagId, tag()); diff --git a/src/datasets.cpp b/src/datasets.cpp index 00fc47e5b9..8f1f4e9a07 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -11,6 +11,8 @@ #include "i18n.h" // NLS support. #include "types.hpp" +#include "image_int.hpp" + #include #include #include @@ -410,9 +412,7 @@ std::string IptcDataSets::dataSetName(uint16_t number, uint16_t recordId) { if (int idx = dataSetIdx(number, recordId); idx != -1) return records_[recordId][idx].name_; - std::ostringstream os; - os << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << number; - return os.str(); + return stringFormat("0x{:04x}", number); } const char* IptcDataSets::dataSetTitle(uint16_t number, uint16_t recordId) { @@ -462,9 +462,7 @@ std::string IptcDataSets::recordName(uint16_t recordId) { return recordInfo_[recordId].name_; } - std::ostringstream os; - os << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << recordId; - return os.str(); + return stringFormat("0x{:04x}", recordId); } const char* IptcDataSets::recordDesc(uint16_t recordId) { diff --git a/src/minoltamn_int.cpp b/src/minoltamn_int.cpp index 3192a037b9..9f180b1ca3 100644 --- a/src/minoltamn_int.cpp +++ b/src/minoltamn_int.cpp @@ -4,6 +4,7 @@ #include "minoltamn_int.hpp" #include "exif.hpp" #include "i18n.h" // NLS support. +#include "image_int.hpp" #include "makernote_int.hpp" #include "tags_int.hpp" #include "value.hpp" @@ -331,17 +332,15 @@ std::ostream& MinoltaMakerNote::printMinoltaFocalLengthStd(std::ostream& os, con std::ostream& MinoltaMakerNote::printMinoltaDateStd(std::ostream& os, const Value& value, const ExifData*) { // From the PHP JPEG Metadata Toolkit - os << value.toInt64() / 65536 << ":" << std::right << std::setw(2) << std::setfill('0') - << (value.toInt64() - value.toInt64() / 65536 * 65536) / 256 << ":" << std::right << std::setw(2) - << std::setfill('0') << value.toInt64() % 256; + auto val = value.toInt64(); + os << stringFormat("{}:{:02}:{:02}", val / 65536, (val % 65536) / 256, val % 256); return os; } std::ostream& MinoltaMakerNote::printMinoltaTimeStd(std::ostream& os, const Value& value, const ExifData*) { // From the PHP JPEG Metadata Toolkit - os << std::right << std::setw(2) << std::setfill('0') << value.toInt64() / 65536 << ":" << std::right << std::setw(2) - << std::setfill('0') << (value.toInt64() - value.toInt64() / 65536 * 65536) / 256 << ":" << std::right - << std::setw(2) << std::setfill('0') << value.toInt64() % 256; + auto val = value.toInt64(); + os << stringFormat("{:02}:{:02}:{:02}", val / 65536, (val % 65536) / 256, val % 256); return os; } diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index b683010e83..d9b8e49be2 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -5,6 +5,7 @@ #include "exif.hpp" #include "i18n.h" // NLS support. +#include "image_int.hpp" #include "makernote_int.hpp" #include "tags_int.hpp" #include "utils.hpp" @@ -3299,10 +3300,9 @@ std::ostream& Nikon3MakerNote::printLensId(std::ostream& os, const Value& value, // #1034 const std::string undefined("undefined"); const std::string section("nikon"); - std::ostringstream lensIDStream; - lensIDStream << static_cast(raw[7]); - if (Internal::readExiv2Config(section, lensIDStream.str(), undefined) != undefined) { - return os << Internal::readExiv2Config(section, lensIDStream.str(), undefined); + auto lensIDStream = std::to_string(raw[7]); + if (Internal::readExiv2Config(section, lensIDStream, undefined) != undefined) { + return os << Internal::readExiv2Config(section, lensIDStream, undefined); } } @@ -3898,10 +3898,9 @@ std::ostream& Nikon3MakerNote::printTimeZone(std::ostream& os, const Value& valu std::ostringstream oss; oss.copyfmt(os); char sign = value.toInt64() < 0 ? '-' : '+'; - long h = static_cast(std::abs(static_cast(value.toFloat() / 60.0F))) % 24; - long min = static_cast(std::abs(static_cast(value.toFloat() - (h * 60)))) % 60; - os << std::fixed << "UTC " << sign << std::setw(2) << std::setfill('0') << h << ":" << std::setw(2) - << std::setfill('0') << min; + long h = static_cast(std::fabs(value.toFloat() / 60.0F)) % 24; + long min = static_cast(std::fabs(value.toFloat() - (h * 60))) % 60; + os << stringFormat("UTC {}{:02}:{:02}", sign, h, min); os.copyfmt(oss); os.flags(f); return os; diff --git a/src/panasonicmn_int.cpp b/src/panasonicmn_int.cpp index 726859f514..b51c17199b 100644 --- a/src/panasonicmn_int.cpp +++ b/src/panasonicmn_int.cpp @@ -3,6 +3,7 @@ // included header files #include "panasonicmn_int.hpp" #include "i18n.h" // NLS support. +#include "image_int.hpp" #include "tags_int.hpp" #include "types.hpp" #include "value.hpp" @@ -619,9 +620,7 @@ std::ostream& PanasonicMakerNote::print0x0029(std::ostream& os, const Value& val std::ostringstream oss; oss.copyfmt(os); const auto time = value.toInt64(); - os << std::setw(2) << std::setfill('0') << time / 360000 << ":" << std::setw(2) << std::setfill('0') - << (time % 360000) / 6000 << ":" << std::setw(2) << std::setfill('0') << (time % 6000) / 100 << "." << std::setw(2) - << std::setfill('0') << time % 100; + os << stringFormat("{:02}:{:02}:{:02}.{:02}", time / 360000, (time % 360000) / 6000, (time % 6000) / 100, time % 100); os.copyfmt(oss); return os; diff --git a/src/pentaxmn_int.cpp b/src/pentaxmn_int.cpp index 78b32ee47b..87b0d283fb 100644 --- a/src/pentaxmn_int.cpp +++ b/src/pentaxmn_int.cpp @@ -4,6 +4,7 @@ #include "pentaxmn_int.hpp" #include "exif.hpp" #include "i18n.h" // NLS support. +#include "image_int.hpp" #include "makernote_int.hpp" #include "tags.hpp" #include "types.hpp" @@ -915,21 +916,14 @@ std::ostream& PentaxMakerNote::printResolution(std::ostream& os, const Value& va std::ostream& PentaxMakerNote::printDate(std::ostream& os, const Value& value, const ExifData*) { /* I choose same format as is used inside EXIF itself */ - os << ((static_cast(value.toInt64(0)) << 8) + value.toInt64(1)); - os << ":"; - os << std::setw(2) << std::setfill('0') << value.toInt64(2); - os << ":"; - os << std::setw(2) << std::setfill('0') << value.toInt64(3); + os << stringFormat("{}:{:02}:{:02}", ((static_cast(value.toInt64(0)) << 8) + value.toInt64(1)), + value.toInt64(2), value.toInt64(3)); return os; } std::ostream& PentaxMakerNote::printTime(std::ostream& os, const Value& value, const ExifData*) { std::ios::fmtflags f(os.flags()); - os << std::setw(2) << std::setfill('0') << value.toInt64(0); - os << ":"; - os << std::setw(2) << std::setfill('0') << value.toInt64(1); - os << ":"; - os << std::setw(2) << std::setfill('0') << value.toInt64(2); + os << stringFormat("{:02}:{:02}:{:02}", value.toInt64(0), value.toInt64(1), value.toInt64(2)); os.flags(f); return os; } diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index 6510fc8f8d..363b0a6fd5 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -6,6 +6,7 @@ #include "error.hpp" #include "exif.hpp" #include "i18n.h" // NLS support. +#include "image_int.hpp" #include "minoltamn_int.hpp" #include "tiffcomposite_int.hpp" #include "utils.hpp" @@ -1239,10 +1240,8 @@ std::ostream& SonyMakerNote::printPixelShiftInfo(std::ostream& os, const Value& std::ios::fmtflags f(os.flags()); - os << "Group " << std::setw(2) << std::setfill('0') << ((groupID >> 17) & 0x1f) << std::setw(2) << std::setfill('0') - << ((groupID >> 12) & 0x1f) << std::setw(2) << std::setfill('0') << ((groupID >> 6) & 0x3f) << std::setw(2) - << std::setfill('0') << (groupID & 0x3f); - + os << stringFormat("Group {:02}{:02}{:02}{:02}", (groupID >> 17) & 0x1f, (groupID >> 12) & 0x1f, + (groupID >> 6) & 0x3f, groupID & 0x3f); os << ", Shot " << value.toUint32(4) << "/" << value.toUint32(5) << " (0x" << std::hex << (groupID >> 22) << ")"; os.flags(f); return os; diff --git a/src/tags.cpp b/src/tags.cpp index 2426c0bcfc..5b1c4ce161 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -46,9 +46,7 @@ constexpr SectionInfo sectionInfo[] = { namespace Exiv2::Internal { bool TagVocabulary::operator==(const std::string& key) const { - if (strlen(voc_) > key.size()) - return false; - return 0 == strcmp(voc_, key.c_str() + key.size() - strlen(voc_)); + return key.rfind(voc_) != std::string::npos; } // Unknown Tag diff --git a/src/value.cpp b/src/value.cpp index ee86d8557d..298370293a 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -8,6 +8,8 @@ #include "error.hpp" #include "types.hpp" +#include "image_int.hpp" + // + standard includes #include @@ -841,8 +843,7 @@ DateValue* DateValue::clone_() const { std::ostream& DateValue::write(std::ostream& os) const { // Write DateValue in ISO 8601 Extended format: YYYY-MM-DD std::ios::fmtflags f(os.flags()); - os << std::setw(4) << std::setfill('0') << date_.year << '-' << std::right << std::setw(2) << std::setfill('0') - << date_.month << '-' << std::setw(2) << std::setfill('0') << date_.day; + os << stringFormat("{:04}-{:02}-{:02}", date_.year, date_.month, date_.day); os.flags(f); return os; } @@ -1023,9 +1024,8 @@ std::ostream& TimeValue::write(std::ostream& os) const { plusMinus = '-'; std::ios::fmtflags f(os.flags()); - os << std::right << std::setw(2) << std::setfill('0') << time_.hour << ':' << std::setw(2) << std::setfill('0') - << time_.minute << ':' << std::setw(2) << std::setfill('0') << time_.second << plusMinus << std::setw(2) - << std::setfill('0') << abs(time_.tzHour) << ':' << std::setw(2) << std::setfill('0') << abs(time_.tzMinute); + os << stringFormat("{:02}:{:02}:{:02}{}{:02}:{:02}", time_.hour, time_.minute, time_.second, plusMinus, + std::abs(time_.tzHour), std::abs(time_.tzMinute)); os.flags(f); return os; diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 172c389047..875bbe16b8 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -13,8 +13,8 @@ #include namespace { -constexpr auto xmlHeader = "\n"; -const auto xmlHdrCnt = static_cast(std::strlen(xmlHeader)); // without the trailing 0-character +constexpr char xmlHeader[] = "\n"; +constexpr auto xmlHdrCnt = std::size(xmlHeader) - 1; // without the trailing 0-character constexpr auto xmlFooter = ""; } // namespace