deleted more stringstrem #25

Merged
wt merged 1 commits from delete-more-stringstream into main 2025-04-17 16:57:09 +07:00
3 changed files with 20 additions and 24 deletions
+12 -13
View File
@@ -1,5 +1,4 @@
#include "qrtosvg.hpp"
#include <sstream>
#include <climits>
std::string toSvgString(const qrcodegen::QrCode& qr, int border)
@@ -9,23 +8,23 @@ std::string toSvgString(const qrcodegen::QrCode& qr, int border)
if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize())
throw std::overflow_error("Border too large");
std::ostringstream sb;
sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
sb << (qr.getSize() + border * 2) << " " << (qr.getSize() + border * 2) << "\" stroke=\"none\">\n";
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
sb << "\t<path d=\"";
std::string sb = "";
sb += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
sb += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
sb += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
+ std::to_string(qr.getSize() + border * 2) + " " + std::to_string(qr.getSize() + border * 2) + "\" stroke=\"none\">\n"
+ "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n"
+ "\t<path d=\"";
for (int y = 0; y < qr.getSize(); y++) {
for (int x = 0; x < qr.getSize(); x++) {
if (qr.getModule(x, y)) {
if (x != 0 || y != 0)
sb << " ";
sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
sb += " ";
sb += "M" + std::to_string(x + border) + "," + std::to_string(y + border) + "h1v1h-1z";
}
}
}
sb << "\" fill=\"#000000\"/>\n";
sb << "</svg>\n";
return sb.str();
sb += "\" fill=\"#000000\"/>\n";
sb += "</svg>\n";
return sb;
}
-1
View File
@@ -3,7 +3,6 @@
#include <types.hpp>
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <syslog.h>
#include <auth/auth.hpp>
+8 -10
View File
@@ -2,7 +2,6 @@
#ifdef __linux__
#include <sys/sysinfo.h>
#endif // __linux__
#include <sstream>
#include <types.hpp>
namespace api
@@ -15,15 +14,14 @@ namespace api
struct sysinfo x;
if (sysinfo(&x) == 0)
{
std::stringstream responsedata;
responsedata << R"({"uptime":{"hour":")"
<< static_cast<unsigned long long>(x.uptime) / 3600ULL
<< R"(","minute":")"
<< static_cast<unsigned long long>(x.uptime) / 60ULL % 60ULL
<< R"(","second":")"
<< static_cast<unsigned long long>(x.uptime) % 60ULL
<< R"("}})";
response.set_content(responsedata.str(), JSON_TYPE);
std::string responsedata(R"({"uptime":{"hour":")"
+ std::to_string(static_cast<unsigned long long>(x.uptime) / 3600ULL)
+ R"(","minute":")"
+ std::to_string(static_cast<unsigned long long>(x.uptime) / 60ULL % 60ULL)
+ R"(","second":")"
+ std::to_string(static_cast<unsigned long long>(x.uptime) % 60ULL)
+ R"("}})");
response.set_content(responsedata, JSON_TYPE);
return;
}
response.set_content(R"({"error":"unknown"})", JSON_TYPE);