changed display write method

This commit is contained in:
Johannes Wendel
2018-11-08 18:25:10 +01:00
parent c1d228b477
commit c53b6af33e

View File

@@ -31,10 +31,6 @@ template<int DigitCount>
void Display<DigitCount>::write_score(int score)
{
auto score_string = std::to_string(score);
if (score_string.length() > DigitCount)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
}
auto score_c_string = this->fit_string(score_string).c_str();
@@ -44,15 +40,16 @@ void Display<DigitCount>::write_score(int score)
template<int DigitCount>
std::string Display<DigitCount>::fit_string(std::string& score_string)
{
auto score_length = score_string.length();
for (int i = 0; i < DigitCount; i++)
{
score_string = " " + score_string;
}
score_length = score_string.length();
auto score_length = score_string.length();
if (score_length > DigitCount)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
return score_string.substr(score_length-DigitCount, score_length);
}
score_string.insert(0, DigitCount-score_length, ' ');
return score_string;
}
template<int DigitCount>