Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some cleanups #3109

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/conntest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.");
}
Expand Down
10 changes: 4 additions & 6 deletions src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "i18n.h" // NLS support.
#include "types.hpp"

#include "image_int.hpp"

#include <array>
#include <iomanip>
#include <sstream>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions src/minoltamn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
15 changes: 7 additions & 8 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<int>(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);
}
}

Expand Down Expand Up @@ -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<long>(std::abs(static_cast<int>(value.toFloat() / 60.0F))) % 24;
long min = static_cast<long>(std::abs(static_cast<int>(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<long>(std::fabs<int>(value.toFloat() / 60.0F)) % 24;
long min = static_cast<long>(std::fabs<int>(value.toFloat() - (h * 60))) % 60;
os << stringFormat("UTC {}{:02}:{:02}", sign, h, min);
os.copyfmt(oss);
os.flags(f);
return os;
Expand Down
5 changes: 2 additions & 3 deletions src/panasonicmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/pentaxmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<uint16_t>(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<uint16_t>(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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/sonymn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "error.hpp"
#include "types.hpp"

#include "image_int.hpp"

// + standard includes
#include <sstream>

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/xmpsidecar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <iostream>

namespace {
constexpr auto xmlHeader = "<?xpacket begin=\"\xef\xbb\xbf\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n";
const auto xmlHdrCnt = static_cast<long>(std::strlen(xmlHeader)); // without the trailing 0-character
constexpr char xmlHeader[] = "<?xpacket begin=\"\xef\xbb\xbf\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n";
constexpr auto xmlHdrCnt = std::size(xmlHeader) - 1; // without the trailing 0-character
constexpr auto xmlFooter = "<?xpacket end=\"w\"?>";
} // namespace

Expand Down
Loading