mirror of https://github.com/kiwix/libkiwix.git
Better beautifyInteger and beautifyFileSize.
This commit is contained in:
parent
be6dc01b4f
commit
9c0f9696ed
|
@ -35,8 +35,8 @@ namespace kiwix
|
||||||
{
|
{
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
|
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(uint64_t number);
|
||||||
std::string beautifyFileSize(const unsigned int number);
|
std::string beautifyFileSize(uint64_t number);
|
||||||
void printStringInHexadecimal(const char* s);
|
void printStringInHexadecimal(const char* s);
|
||||||
void printStringInHexadecimal(icu::UnicodeString s);
|
void printStringInHexadecimal(icu::UnicodeString s);
|
||||||
void stringReplacement(std::string& str,
|
void stringReplacement(std::string& str,
|
||||||
|
|
|
@ -60,7 +60,7 @@ std::string kiwix::removeAccents(const std::string& text)
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
|
|
||||||
/* Prepare integer for display */
|
/* Prepare integer for display */
|
||||||
std::string kiwix::beautifyInteger(const unsigned int number)
|
std::string kiwix::beautifyInteger(uint64_t number)
|
||||||
{
|
{
|
||||||
std::stringstream numberStream;
|
std::stringstream numberStream;
|
||||||
numberStream << number;
|
numberStream << number;
|
||||||
|
@ -75,14 +75,19 @@ std::string kiwix::beautifyInteger(const unsigned int number)
|
||||||
return numberString;
|
return numberString;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string kiwix::beautifyFileSize(const unsigned int number)
|
std::string kiwix::beautifyFileSize(uint64_t number)
|
||||||
{
|
{
|
||||||
if (number > 1024 * 1024) {
|
std::stringstream ss;
|
||||||
return kiwix::beautifyInteger(number / (1024 * 1024)) + " GB";
|
ss << std::fixed << std::setprecision(2);
|
||||||
} else {
|
if (number>>30)
|
||||||
return kiwix::beautifyInteger(number / 1024 != 0 ? number / 1024 : 1)
|
ss << (number/(1024.0*1024*1024)) << " GB";
|
||||||
+ " MB";
|
else if (number>>20)
|
||||||
}
|
ss << (number/(1024.0*1024)) << " MB";
|
||||||
|
else if (number>>10)
|
||||||
|
ss << (number/1024.0) << " KB";
|
||||||
|
else
|
||||||
|
ss << number << " B";
|
||||||
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void kiwix::printStringInHexadecimal(icu::UnicodeString s)
|
void kiwix::printStringInHexadecimal(icu::UnicodeString s)
|
||||||
|
|
Loading…
Reference in New Issue