From c53b6af33e37be0f4732a7fbe8e7b9deed279b87 Mon Sep 17 00:00:00 2001 From: Johannes Wendel Date: Thu, 8 Nov 2018 18:25:10 +0100 Subject: [PATCH] changed display write method --- FlippR-Driver/src/output/Display.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/FlippR-Driver/src/output/Display.cpp b/FlippR-Driver/src/output/Display.cpp index c834736..deb0484 100644 --- a/FlippR-Driver/src/output/Display.cpp +++ b/FlippR-Driver/src/output/Display.cpp @@ -31,10 +31,6 @@ template void Display::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::write_score(int score) template std::string Display::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