16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 18:09:18 +02:00

Remove not needed to_string overloads and refactor existing one

This commit is contained in:
docentYT
2026-05-01 13:15:33 +02:00
parent b59ccb6de5
commit e1d8c08915
2 changed files with 22 additions and 48 deletions

View File

@@ -175,57 +175,46 @@ std::pair<std::string, int> split_string_and_number(std::string const &Key)
return {Key, 0};
}
std::string to_string(int Value)
{
std::ostringstream o;
o << Value;
return o.str();
};
std::string to_string(unsigned int Value)
{
std::ostringstream o;
o << Value;
return o.str();
};
std::string to_string(double Value)
{
std::ostringstream o;
o << Value;
return o.str();
};
std::string to_string(int Value, int width)
{
std::ostringstream o;
o.width(width);
o << Value;
return o.str();
o << std::setw(width) << Value;
return std::move(o).str();
};
std::string to_string(double Value, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision);
o << Value;
return o.str();
o << std::fixed << std::setprecision(precision) << Value;
return std::move(o).str();
};
std::string to_string(double const Value, int const Precision, int const Width)
{
std::ostringstream converter;
converter << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
return converter.str();
std::ostringstream o;
o << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
return std::move(o).str();
};
std::string to_hex_str(int const Value, int const Width)
{
std::ostringstream converter;
converter << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
return converter.str();
std::ostringstream o;
o << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
return o.str();
};
std::string const fractionlabels[] = {" ", "¹", "²", "³", "", "", "", "", "", ""};
std::string to_minutes_str(float const Minutes, bool const Leadingzero, int const Width)
{
float minutesintegral;
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
auto const width{Width - 1};
auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
return (minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))]);
}
bool string_ends_with(const std::string &string, const std::string &ending)
{
if (string.length() < ending.length())
@@ -242,18 +231,6 @@ bool string_starts_with(const std::string &string, const std::string &begin)
return string.compare(0, begin.length(), begin) == 0;
}
std::string const fractionlabels[] = {" ", "¹", "²", "³", "", "", "", "", "", ""};
std::string to_minutes_str(float const Minutes, bool const Leadingzero, int const Width)
{
float minutesintegral;
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
auto const width{Width - 1};
auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
return (minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))]);
}
int stol_def(const std::string &str, const int &DefaultValue)
{