mirror of
https://github.com/textmate/textmate.git
synced 2026-01-24 22:27:56 -05:00
33 lines
563 B
C++
33 lines
563 B
C++
#include "format.h"
|
|
|
|
namespace text
|
|
{
|
|
std::string format_size (size_t inBytes)
|
|
{
|
|
double size = (double)inBytes;
|
|
char const* unitStr = inBytes == 1 ? "byte" : "bytes";
|
|
|
|
if(inBytes > 1000 * 1024*1024)
|
|
{
|
|
size /= 1024*1024*1024;
|
|
unitStr = "GiB";
|
|
}
|
|
else if(inBytes > 1000 * 1024)
|
|
{
|
|
size /= 1024*1024;
|
|
unitStr = "MiB";
|
|
}
|
|
else if(inBytes > 1000)
|
|
{
|
|
size /= 1024;
|
|
unitStr = "KiB";
|
|
}
|
|
else
|
|
{
|
|
return text::format("%zu %s", inBytes, unitStr);
|
|
}
|
|
|
|
return text::format("%.1f %s", size, unitStr);
|
|
}
|
|
|
|
} /* text */ |