17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-28 23:57:28 +01:00

refactor(sonar): more small fixes

- std::format instead of iostream manipulators in to_string/to_hex_str (cpp:S6495);
  output verified identical, negative hex values keep the unsigned form
- remove an empty compound statement (cpp:S108)
- drop an always-false unsigned < 0 branch (cpp:S1768)
- explicit lambda capture (cpp:S3608)
- std::make_unique (cpp:S5950)
This commit is contained in:
jerrrrycho
2026-10-10 17:52:59 +02:00
parent ba6840b6ba
commit 780ddf9ddb
5 changed files with 7 additions and 14 deletions

View File

@@ -249,23 +249,18 @@ std::string to_string(int Value, int width)
std::string to_string(double Value, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision) << Value;
return std::move(o).str();
return std::format("{:.{}f}", Value, precision);
};
std::string to_string(double const Value, int const Precision, int const Width)
{
std::ostringstream o;
o << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
return std::move(o).str();
return std::format("{:>{}.{}f}", Value, Width, Precision);
};
std::string to_hex_str(int const Value, int const Width)
{
std::ostringstream o;
o << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
return o.str();
// iostreams print negative values in hex as their unsigned representation
return std::format("0x{:0{}X}", static_cast<unsigned int>(Value), Width);
};
std::string const fractionlabels[] = {U8(" "), U8("¹"), U8("²"), U8("³"), U8("⁴"), U8("⁵"), U8("⁶"), U8("⁷"), U8("⁸"), U8("⁹")};