This commit is contained in:
MihailRis 2024-04-14 22:50:35 +03:00
parent f5b3f3c33f
commit a7a447552e
5 changed files with 99 additions and 76 deletions

View File

@ -12,6 +12,7 @@
#include "../physics/Hitbox.h" #include "../physics/Hitbox.h"
#include "../util/stringutil.h" #include "../util/stringutil.h"
#include "../voxels/Block.h" #include "../voxels/Block.h"
#include "../voxels/Chunk.h"
#include "../voxels/Chunks.h" #include "../voxels/Chunks.h"
#include "../world/Level.h" #include "../world/Level.h"
#include "../world/World.h" #include "../world/World.h"

View File

@ -1,5 +1,6 @@
#include "stringutil.h" #include "stringutil.h"
#include <cmath>
#include <vector> #include <vector>
#include <locale> #include <locale>
#include <iomanip> #include <iomanip>
@ -424,3 +425,22 @@ std::vector<std::wstring> util::split(const std::wstring& str, char delimiter) {
} }
return result; 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];
}

View File

@ -54,6 +54,8 @@ namespace util {
extern std::vector<std::string> split(const std::string& str, char delimiter); extern std::vector<std::string> split(const std::string& str, char delimiter);
extern std::vector<std::wstring> split(const std::wstring& str, char delimiter); extern std::vector<std::wstring> split(const std::wstring& str, char delimiter);
extern std::string format_data_size(size_t size);
} }
#endif // UTIL_STRINGUTIL_H_ #endif // UTIL_STRINGUTIL_H_