mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 15:09:19 +02:00
Remove not needed to_string overloads and refactor existing one
This commit is contained in:
@@ -175,57 +175,46 @@ std::pair<std::string, int> split_string_and_number(std::string const &Key)
|
|||||||
return {Key, 0};
|
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::string to_string(int Value, int width)
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
o.width(width);
|
o << std::setw(width) << Value;
|
||||||
o << Value;
|
return std::move(o).str();
|
||||||
return o.str();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string to_string(double Value, int precision)
|
std::string to_string(double Value, int precision)
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
o << std::fixed << std::setprecision(precision);
|
o << std::fixed << std::setprecision(precision) << Value;
|
||||||
o << Value;
|
return std::move(o).str();
|
||||||
return o.str();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string to_string(double const Value, int const Precision, int const Width)
|
std::string to_string(double const Value, int const Precision, int const Width)
|
||||||
{
|
{
|
||||||
std::ostringstream converter;
|
std::ostringstream o;
|
||||||
converter << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
|
o << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
|
||||||
return converter.str();
|
return std::move(o).str();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string to_hex_str(int const Value, int const Width)
|
std::string to_hex_str(int const Value, int const Width)
|
||||||
{
|
{
|
||||||
std::ostringstream converter;
|
std::ostringstream o;
|
||||||
converter << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
|
o << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
|
||||||
return converter.str();
|
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)
|
bool string_ends_with(const std::string &string, const std::string &ending)
|
||||||
{
|
{
|
||||||
if (string.length() < ending.length())
|
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;
|
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)
|
int stol_def(const std::string &str, const int &DefaultValue)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -125,10 +125,7 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability);
|
|||||||
std::vector<std::string> Split(std::string_view s, char delim);
|
std::vector<std::string> Split(std::string_view s, char delim);
|
||||||
std::pair<std::string, int> split_string_and_number(std::string const &Key);
|
std::pair<std::string, int> split_string_and_number(std::string const &Key);
|
||||||
|
|
||||||
std::string to_string(int Value);
|
|
||||||
std::string to_string(unsigned int Value);
|
|
||||||
std::string to_string(int Value, int width);
|
std::string to_string(int Value, int width);
|
||||||
std::string to_string(double Value);
|
|
||||||
std::string to_string(double Value, int precision);
|
std::string to_string(double Value, int precision);
|
||||||
std::string to_string(double Value, int precision, int width);
|
std::string to_string(double Value, int precision, int width);
|
||||||
std::string to_hex_str(int const Value, int const width = 4);
|
std::string to_hex_str(int const Value, int const width = 4);
|
||||||
|
|||||||
Reference in New Issue
Block a user