Skip to content

Commit b8fd4d1

Browse files
committed
fmt conversions
Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent 505dece commit b8fd4d1

File tree

4 files changed

+32
-77
lines changed

4 files changed

+32
-77
lines changed

include/exiv2/asfvideo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EXIV2API AsfVideo : public Image {
8282
// Constructor to create a GUID object from a byte array
8383
explicit GUIDTag(const uint8_t* bytes);
8484

85-
std::string to_string();
85+
std::string to_string() const;
8686

8787
bool operator<(const GUIDTag& other) const;
8888
};

src/asfvideo.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "error.hpp"
1313
#include "futils.hpp"
1414
#include "helper_functions.hpp"
15+
#include "image_int.hpp"
1516
#include "utils.hpp"
1617
// *****************************************************************************
1718
// class member definitions
@@ -58,24 +59,12 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
5859
}
5960
}
6061

61-
std::string AsfVideo::GUIDTag::to_string() {
62-
// Convert each field of the GUID structure to a string
63-
std::stringstream ss;
64-
ss << std::hex << std::setw(8) << std::setfill('0') << data1_ << "-";
65-
ss << std::hex << std::setw(4) << std::setfill('0') << data2_ << "-";
66-
ss << std::hex << std::setw(4) << std::setfill('0') << data3_ << "-";
67-
68-
for (size_t i = 0; i < 8; i++) {
69-
if (i == 2) {
70-
ss << "-";
71-
}
72-
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(data4_[i]);
73-
}
74-
62+
std::string AsfVideo::GUIDTag::to_string() const {
7563
// Concatenate all strings into a single string
7664
// Convert the string to uppercase
7765
// Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E
78-
return Internal::upper(ss.str());
66+
return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_,
67+
data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]);
7968
}
8069

8170
bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const {

src/basicio.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,7 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) {
930930

931931
// generating the name for temp file.
932932
std::time_t timestamp = std::time(nullptr);
933-
std::stringstream ss;
934-
ss << timestamp << XPathIo::TEMP_FILE_EXT;
935-
std::string path = ss.str();
933+
auto path = stringFormat("{}{}", timestamp, XPathIo::TEMP_FILE_EXT);
936934

937935
if (prot == pStdin) {
938936
if (isatty(fileno(stdin)))
@@ -1437,9 +1435,7 @@ void HttpIo::HttpImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st
14371435
request["verb"] = "GET";
14381436
std::string errors;
14391437
if (lowBlock != std::numeric_limits<size_t>::max() && highBlock != std::numeric_limits<size_t>::max()) {
1440-
std::stringstream ss;
1441-
ss << "Range: bytes=" << lowBlock * blockSize_ << "-" << (((highBlock + 1) * blockSize_) - 1) << "\r\n";
1442-
request["header"] = ss.str();
1438+
request["header"] = stringFormat("Range: bytes={}-{}", lowBlock * blockSize_, (highBlock + 1) * (blockSize_ - 1));
14431439
}
14441440

14451441
int serverCode = http(request, responseDic, errors);
@@ -1480,20 +1476,15 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s
14801476
// url encode
14811477
const std::string urlencodeData = urlencode(encodeData.data());
14821478

1483-
std::stringstream ss;
1484-
ss << "path=" << hostInfo_.Path << "&"
1485-
<< "from=" << from << "&"
1486-
<< "to=" << to << "&"
1487-
<< "data=" << urlencodeData;
1488-
std::string postData = ss.str();
1479+
auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo_.Path, from, to, urlencodeData);
14891480

14901481
// create the header
1491-
ss.str("");
1492-
ss << "Content-Length: " << postData.length() << "\n"
1493-
<< "Content-Type: application/x-www-form-urlencoded\n"
1494-
<< "\n"
1495-
<< postData << "\r\n";
1496-
request["header"] = ss.str();
1482+
auto header = stringFormat(
1483+
"Content-Length: {}\n"
1484+
"Content-Type: application/x-www-form-urlencoded\n"
1485+
"\n{}\r\n",
1486+
postData.length(), postData);
1487+
request["header"] = header;
14971488

14981489
int serverCode = http(request, response, errors);
14991490
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
@@ -1616,9 +1607,7 @@ void CurlIo::CurlImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st
16161607
// curl_easy_setopt(curl_, CURLOPT_VERBOSE, 1); // debugging mode
16171608

16181609
if (lowBlock != std::numeric_limits<size_t>::max() && highBlock != std::numeric_limits<size_t>::max()) {
1619-
std::stringstream ss;
1620-
ss << lowBlock * blockSize_ << "-" << (((highBlock + 1) * blockSize_) - 1);
1621-
std::string range = ss.str();
1610+
auto range = stringFormat("{}-{}", lowBlock * blockSize_, (highBlock + 1) * (blockSize_ - 1));
16221611
curl_easy_setopt(curl_, CURLOPT_RANGE, range.c_str());
16231612
}
16241613

@@ -1662,12 +1651,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s
16621651
base64encode(data, size, encodeData.data(), encodeLength);
16631652
// url encode
16641653
const std::string urlencodeData = urlencode(encodeData.data());
1665-
std::stringstream ss;
1666-
ss << "path=" << hostInfo.Path << "&"
1667-
<< "from=" << from << "&"
1668-
<< "to=" << to << "&"
1669-
<< "data=" << urlencodeData;
1670-
std::string postData = ss.str();
1654+
auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo.Path, from, to, urlencodeData);
16711655

16721656
curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, postData.c_str());
16731657
// Perform the request, res will get the return code.

src/rafimage.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,8 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
150150
uint32_t jpg_img_off = Exiv2::getULong(jpg_img_offset, bigEndian);
151151
uint32_t jpg_img_len = Exiv2::getULong(jpg_img_length, bigEndian);
152152
{
153-
std::stringstream j_off;
154-
std::stringstream j_len;
155-
j_off << jpg_img_off;
156-
j_len << jpg_img_len;
157-
out << Internal::indent(depth) << stringFormat(format, address, 4) << " JPEG offset : " << j_off.str() << '\n';
158-
out << Internal::indent(depth) << stringFormat(format, address2, 4) << " JPEG length : " << j_len.str() << '\n';
153+
out << Internal::indent(depth) << stringFormat(format, address, 4) << " JPEG offset : " << jpg_img_off << '\n';
154+
out << Internal::indent(depth) << stringFormat(format, address2, 4) << " JPEG length : " << jpg_img_len << '\n';
159155
}
160156

161157
// RAFs can carry the payload in one or two parts
@@ -170,14 +166,10 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
170166
io_->readOrThrow(data, 4);
171167
meta_len[i] = Exiv2::getULong(data, bigEndian);
172168
{
173-
std::stringstream c_off;
174-
std::stringstream c_len;
175-
c_off << meta_off[i];
176-
c_len << meta_len[i];
177-
out << Internal::indent(depth) << stringFormat(format, address, 4) << "meta offset" << i + 1 << " : "
178-
<< c_off.str() << '\n';
179-
out << Internal::indent(depth) << stringFormat(format, address2, 4) << "meta length" << i + 1 << " : "
180-
<< c_len.str() << '\n';
169+
out << Internal::indent(depth) << stringFormat(format, address, 4)
170+
<< stringFormat("meta offset{} : {}\n", i + 1, meta_off[i]);
171+
out << Internal::indent(depth) << stringFormat(format, address2, 4)
172+
<< stringFormat("meta length{} : {}\n", i + 1, meta_len[i]);
181173
}
182174

183175
address = io_->tell();
@@ -196,26 +188,16 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
196188
io_->readOrThrow(data, 4);
197189
cfa_data[i] = Exiv2::getULong(data, bigEndian);
198190
{
199-
std::stringstream c_off;
200-
std::stringstream c_len;
201-
std::stringstream c_comp;
202-
std::stringstream c_size;
203-
std::stringstream c_data;
204-
c_off << cfa_off[i];
205-
c_len << cfa_len[i];
206-
c_comp << comp[i];
207-
c_size << cfa_size[i];
208-
c_data << cfa_data[i];
209-
out << Internal::indent(depth) << stringFormat(format, address, 4U) << " CFA offset" << i + 1 << " : "
210-
<< c_off.str() << '\n';
211-
out << Internal::indent(depth) << stringFormat(format, address2, 4U) << " CFA length" << i + 1 << " : "
212-
<< c_len.str() << '\n';
213-
out << Internal::indent(depth) << stringFormat(format, address3, 4U) << "compression" << i + 1 << " : "
214-
<< c_comp.str() << '\n';
215-
out << Internal::indent(depth) << stringFormat(format, address4, 4U) << " CFA chunk" << i + 1 << " : "
216-
<< c_size.str() << '\n';
217-
out << Internal::indent(depth) << stringFormat(format, address5, 4U) << " unknown" << i + 1 << " : "
218-
<< c_data.str() << '\n';
191+
out << Internal::indent(depth) << stringFormat(format, address, 4U)
192+
<< stringFormat(" CFA offset{} : {}\n", i + 1, cfa_off[i]);
193+
out << Internal::indent(depth) << stringFormat(format, address2, 4U)
194+
<< stringFormat(" CFA length{} : {}\n", i + 1, cfa_len[i]);
195+
out << Internal::indent(depth) << stringFormat(format, address3, 4U)
196+
<< stringFormat("compression{} : {}\n", i + 1, comp[i]);
197+
out << Internal::indent(depth) << stringFormat(format, address4, 4U)
198+
<< stringFormat(" CFA chunk{} : {}\n", i + 1, cfa_size[i]);
199+
out << Internal::indent(depth) << stringFormat(format, address5, 4U)
200+
<< stringFormat(" unknown{} : {}\n", i + 1, cfa_data[i]);
219201
}
220202
}
221203

0 commit comments

Comments
 (0)