From 5b14d758ebeeed2157b203da6a9aa15454642870 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 --- src/basicio.cpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index 15d0bf7534..4f93ca8bb0 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -929,9 +929,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))) @@ -1437,9 +1435,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); @@ -1480,15 +1477,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" @@ -1615,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::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()); } @@ -1661,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.