mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
idk
This commit is contained in:
parent
f5b3f3c33f
commit
a7a447552e
5 changed files with 99 additions and 76 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "stringutil.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <iomanip>
|
||||
|
|
@ -424,3 +425,22 @@ std::vector<std::wstring> util::split(const std::wstring& str, char delimiter) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string util::format_data_size(size_t size) {
|
||||
if (size < 1024) {
|
||||
return std::to_string(size)+" B";
|
||||
}
|
||||
const std::string postfixes[] {
|
||||
" B", " KiB", " MiB", " GiB", " TiB", " EiB", " PiB"
|
||||
};
|
||||
int group = 0;
|
||||
size_t remainder;
|
||||
while (size >= 1024) {
|
||||
group++;
|
||||
remainder = size % 1024;
|
||||
size /= 1024;
|
||||
}
|
||||
return std::to_string(size)+"."+
|
||||
std::to_string(static_cast<int>(round(remainder/1024.0f)))+
|
||||
postfixes[group];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue