diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index f66eaa18f..bc737a109 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -50,6 +50,15 @@ std::string kiwix::beautifyInteger(const unsigned int number) { return numberString; } +std::string kiwix::beautifyFileSize(const unsigned int number) { + if (number > 1024*1024) { + return kiwix::beautifyInteger(number/(1024*1024)) + " GB"; + } else { + return kiwix::beautifyInteger(number/1024 != + 0 ? number/1024 : 1) + " MB"; + } +} + std::string kiwix::removeAccents(const std::string &text) { loadICUExternalTables(); ucnv_setDefaultName("UTF-8"); diff --git a/src/common/stringTools.h b/src/common/stringTools.h index b197cf067..d83c6ce9f 100644 --- a/src/common/stringTools.h +++ b/src/common/stringTools.h @@ -43,6 +43,7 @@ namespace kiwix { std::string removeAccents(const std::string &text); std::string beautifyInteger(const unsigned int number); + std::string beautifyFileSize(const unsigned int number); std::string urlEncode(const std::string &c); void printStringInHexadecimal(const char *s); void printStringInHexadecimal(UnicodeString s);