From ae55ee7f0bc5d400b2b1f5b4a175add76812c5f2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 14 Jul 2018 21:45:31 +0300 Subject: [PATCH] [General] Add getNumberOfDigits to Utils in components --- components/openmw-mp/Utils.cpp | 14 +++++++++++++- components/openmw-mp/Utils.hpp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index a4a4b6e7b..bca6ca3bd 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -54,7 +54,7 @@ void Utils::timestamp() printf("%s", t); } -// http://stackoverflow.com/questions/1637587/c-libcurl-console-progress-bar +// Based on http://stackoverflow.com/questions/1637587/c-libcurl-console-progress-bar int Utils::progressFunc(double TotalToDownload, double NowDownloaded) { // how wide you want the progress meter to be @@ -85,6 +85,18 @@ bool Utils::compareDoubles(double a, double b, double epsilon) return fabs(a - b) < epsilon; } +// Based on https://stackoverflow.com/a/1489873 +unsigned int Utils::getNumberOfDigits(int integer) +{ + int digits = 0; + if (integer < 0) digits = 1; + while (integer) { + integer /= 10; + digits++; + } + return digits; +} + std::string Utils::toString(int num) { std::ostringstream stream; diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 74101f038..c18e29231 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -26,6 +26,7 @@ namespace Utils int progressFunc(double TotalToDownload, double NowDownloaded); + unsigned int getNumberOfDigits(int integer); bool compareDoubles(double a, double b, double epsilon); template