mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 02:19:44 +00:00
add util::format_count
This commit is contained in:
parent
d857e7326d
commit
d4deb34722
2 changed files with 44 additions and 24 deletions
|
|
@ -667,6 +667,25 @@ std::string util::format_data_size(size_t size) {
|
||||||
postfixes[group];
|
postfixes[group];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string util::format_count(size_t count) {
|
||||||
|
if (count < 1000) {
|
||||||
|
return std::to_string(count);
|
||||||
|
}
|
||||||
|
const std::string postfixes[] {
|
||||||
|
"", " K", " M", " B"
|
||||||
|
};
|
||||||
|
int group = 0;
|
||||||
|
size_t remainder = 0;
|
||||||
|
while (count >= 1000) {
|
||||||
|
group++;
|
||||||
|
remainder = count % 1000;
|
||||||
|
count /= 1000;
|
||||||
|
}
|
||||||
|
return std::to_string(count) + "." +
|
||||||
|
std::to_string(static_cast<int>(round(remainder / 1000.0f))) +
|
||||||
|
postfixes[group];
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<std::string, std::string> util::split_at(
|
std::pair<std::string, std::string> util::split_at(
|
||||||
std::string_view view, char c
|
std::string_view view, char c
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ namespace util {
|
||||||
std::vector<std::wstring> split(const std::wstring& str, char delimiter);
|
std::vector<std::wstring> split(const std::wstring& str, char delimiter);
|
||||||
|
|
||||||
std::string format_data_size(size_t size);
|
std::string format_data_size(size_t size);
|
||||||
|
std::string format_count(size_t size);
|
||||||
|
|
||||||
std::pair<std::string, std::string> split_at(std::string_view view, char c);
|
std::pair<std::string, std::string> split_at(std::string_view view, char c);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue