From 03db7b3a9757d80d01175880d35ceb09f4fc2c75 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 26 Nov 2023 13:55:18 -0800 Subject: [PATCH] fmt conversions Signed-off-by: Rosen Penev --- include/exiv2/asfvideo.hpp | 2 +- src/asfvideo.cpp | 19 ++++--------------- src/basicio.cpp | 29 +++++++---------------------- 3 files changed, 12 insertions(+), 38 deletions(-) diff --git a/include/exiv2/asfvideo.hpp b/include/exiv2/asfvideo.hpp index b9c5f597fc..57d10a5708 100644 --- a/include/exiv2/asfvideo.hpp +++ b/include/exiv2/asfvideo.hpp @@ -81,7 +81,7 @@ class EXIV2API AsfVideo : public Image { // Constructor to create a GUID object from a byte array explicit GUIDTag(const uint8_t* bytes); - std::string to_string(); + std::string to_string() const; bool operator<(const GUIDTag& other) const; }; diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp index 5016ffdb8c..68ba631ba5 100644 --- a/src/asfvideo.cpp +++ b/src/asfvideo.cpp @@ -12,6 +12,7 @@ #include "error.hpp" #include "futils.hpp" #include "helper_functions.hpp" +#include "image_int.hpp" #include "utils.hpp" // ***************************************************************************** // class member definitions @@ -58,24 +59,12 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { } } -std::string AsfVideo::GUIDTag::to_string() { - // Convert each field of the GUID structure to a string - std::stringstream ss; - ss << std::hex << std::setw(8) << std::setfill('0') << data1_ << "-"; - ss << std::hex << std::setw(4) << std::setfill('0') << data2_ << "-"; - ss << std::hex << std::setw(4) << std::setfill('0') << data3_ << "-"; - - for (size_t i = 0; i < 8; i++) { - if (i == 2) { - ss << "-"; - } - ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(data4_[i]); - } - +std::string AsfVideo::GUIDTag::to_string() const { // Concatenate all strings into a single string // Convert the string to uppercase // Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E - return Internal::upper(ss.str()); + return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_, + data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]); } bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const { diff --git a/src/basicio.cpp b/src/basicio.cpp index 3971cb50ce..f0870a81c6 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -930,9 +930,7 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) { // generating the name for temp file. std::time_t timestamp = std::time(nullptr); - std::stringstream ss; - ss << timestamp << XPathIo::TEMP_FILE_EXT; - std::string path = ss.str(); + auto path = stringFormat("{}{}", timestamp, XPathIo::TEMP_FILE_EXT); if (prot == pStdin) { if (isatty(fileno(stdin))) @@ -1438,9 +1436,8 @@ void HttpIo::HttpImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st request["verb"] = "GET"; std::string errors; if (lowBlock != std::numeric_limits::max() && highBlock != std::numeric_limits::max()) { - std::stringstream ss; - ss << "Range: bytes=" << lowBlock * blockSize_ << "-" << ((highBlock + 1) * blockSize_ - 1) << "\r\n"; - request["header"] = ss.str(); + auto ss = stringFormat("Range: bytes={}-{}", lowBlock * blockSize_, ((highBlock + 1) * blockSize_ - 1)); + request["header"] = ss; } int serverCode = http(request, responseDic, errors); @@ -1481,15 +1478,10 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s // url encode const std::string urlencodeData = urlencode(encodeData.data()); - std::stringstream ss; - ss << "path=" << hostInfo_.Path << "&" - << "from=" << from << "&" - << "to=" << to << "&" - << "data=" << urlencodeData; - std::string postData = ss.str(); + auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo_.Path, from, to, urlencodeData); // create the header - ss.str(""); + std::stringstream ss; ss << "Content-Length: " << postData.length() << "\n" << "Content-Type: application/x-www-form-urlencoded\n" << "\n" @@ -1617,9 +1609,7 @@ void CurlIo::CurlImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st // curl_easy_setopt(curl_, CURLOPT_VERBOSE, 1); // debugging mode if (lowBlock != std::numeric_limits::max() && highBlock != std::numeric_limits::max()) { - std::stringstream ss; - ss << lowBlock * blockSize_ << "-" << ((highBlock + 1) * blockSize_ - 1); - std::string range = ss.str(); + auto range = stringFormat("{}-{}", lowBlock * blockSize_, ((highBlock + 1) * blockSize_ - 1)); curl_easy_setopt(curl_, CURLOPT_RANGE, range.c_str()); } @@ -1663,12 +1653,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s base64encode(data, size, encodeData.data(), encodeLength); // url encode const std::string urlencodeData = urlencode(encodeData.data()); - std::stringstream ss; - ss << "path=" << hostInfo.Path << "&" - << "from=" << from << "&" - << "to=" << to << "&" - << "data=" << urlencodeData; - std::string postData = ss.str(); + auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo.Path, from, to, urlencodeData); curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, postData.c_str()); // Perform the request, res will get the return code.