Skip to content

Commit

Permalink
fmt conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 7, 2025
1 parent 1fa93bd commit 75d23f7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 77 deletions.
2 changes: 1 addition & 1 deletion include/exiv2/asfvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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;
};
Expand Down
19 changes: 4 additions & 15 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "error.hpp"
#include "futils.hpp"
#include "helper_functions.hpp"
#include "image_int.hpp"
#include "utils.hpp"
// *****************************************************************************
// class member definitions
Expand Down Expand Up @@ -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<int>(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 {
Expand Down
38 changes: 11 additions & 27 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -1437,9 +1435,7 @@ void HttpIo::HttpImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st
request["verb"] = "GET";
std::string errors;
if (lowBlock != std::numeric_limits<size_t>::max() && highBlock != std::numeric_limits<size_t>::max()) {
std::stringstream ss;
ss << "Range: bytes=" << lowBlock * blockSize_ << "-" << (((highBlock + 1) * blockSize_) - 1) << "\r\n";
request["header"] = ss.str();
request["header"] = stringFormat("Range: bytes={}-{}", lowBlock * blockSize_, (highBlock + 1) * (blockSize_ - 1));
}

int serverCode = http(request, responseDic, errors);
Expand Down Expand Up @@ -1480,20 +1476,15 @@ 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("");
ss << "Content-Length: " << postData.length() << "\n"
<< "Content-Type: application/x-www-form-urlencoded\n"
<< "\n"
<< postData << "\r\n";
request["header"] = ss.str();
auto header = stringFormat(
"Content-Length: {}\n"
"Content-Type: application/x-www-form-urlencoded\n"
"\n{}\r\n",
postData.length(), postData);
request["header"] = header;

int serverCode = http(request, response, errors);
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
Expand Down Expand Up @@ -1616,9 +1607,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<size_t>::max() && highBlock != std::numeric_limits<size_t>::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());
}

Expand Down Expand Up @@ -1662,12 +1651,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.
Expand Down
50 changes: 16 additions & 34 deletions src/rafimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
uint32_t jpg_img_off = Exiv2::getULong(jpg_img_offset, bigEndian);
uint32_t jpg_img_len = Exiv2::getULong(jpg_img_length, bigEndian);
{
std::stringstream j_off;
std::stringstream j_len;
j_off << jpg_img_off;
j_len << jpg_img_len;
out << Internal::indent(depth) << stringFormat(format, address, 4) << " JPEG offset : " << j_off.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address2, 4) << " JPEG length : " << j_len.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address, 4) << " JPEG offset : " << jpg_img_off << '\n';
out << Internal::indent(depth) << stringFormat(format, address2, 4) << " JPEG length : " << jpg_img_len << '\n';
}

// RAFs can carry the payload in one or two parts
Expand All @@ -170,14 +166,10 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
io_->readOrThrow(data, 4);
meta_len[i] = Exiv2::getULong(data, bigEndian);
{
std::stringstream c_off;
std::stringstream c_len;
c_off << meta_off[i];
c_len << meta_len[i];
out << Internal::indent(depth) << stringFormat(format, address, 4) << "meta offset" << i + 1 << " : "
<< c_off.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address2, 4) << "meta length" << i + 1 << " : "
<< c_len.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address, 4)
<< stringFormat("meta offset{} : {}\n", i + 1, meta_off[i]);
out << Internal::indent(depth) << stringFormat(format, address2, 4)
<< stringFormat("meta length{} : {}\n", i + 1, meta_len[i]);
}

address = io_->tell();
Expand All @@ -196,26 +188,16 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
io_->readOrThrow(data, 4);
cfa_data[i] = Exiv2::getULong(data, bigEndian);
{
std::stringstream c_off;
std::stringstream c_len;
std::stringstream c_comp;
std::stringstream c_size;
std::stringstream c_data;
c_off << cfa_off[i];
c_len << cfa_len[i];
c_comp << comp[i];
c_size << cfa_size[i];
c_data << cfa_data[i];
out << Internal::indent(depth) << stringFormat(format, address, 4U) << " CFA offset" << i + 1 << " : "
<< c_off.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address2, 4U) << " CFA length" << i + 1 << " : "
<< c_len.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address3, 4U) << "compression" << i + 1 << " : "
<< c_comp.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address4, 4U) << " CFA chunk" << i + 1 << " : "
<< c_size.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address5, 4U) << " unknown" << i + 1 << " : "
<< c_data.str() << '\n';
out << Internal::indent(depth) << stringFormat(format, address, 4U)
<< stringFormat(" CFA offset{} : {}\n", i + 1, cfa_off[i]);
out << Internal::indent(depth) << stringFormat(format, address2, 4U)
<< stringFormat(" CFA length{} : {}\n", i + 1, cfa_len[i]);
out << Internal::indent(depth) << stringFormat(format, address3, 4U)
<< stringFormat("compression{} : {}\n", i + 1, comp[i]);
out << Internal::indent(depth) << stringFormat(format, address4, 4U)
<< stringFormat(" CFA chunk{} : {}\n", i + 1, cfa_size[i]);
out << Internal::indent(depth) << stringFormat(format, address5, 4U)
<< stringFormat(" unknown{} : {}\n", i + 1, cfa_data[i]);
}
}

Expand Down

0 comments on commit 75d23f7

Please sign in to comment.