adapted from GM9i's byte parsing. */
| 72 | adapted from GM9i's byte parsing. |
| 73 | */ |
| 74 | std::string StringUtils::formatBytes(u64 bytes) { |
| 75 | char out[32]; |
| 76 | |
| 77 | if (bytes == 1) snprintf(out, sizeof(out), "%lld Byte", bytes); |
| 78 | else if (bytes < 1ull << 10) snprintf(out, sizeof(out), "%lld Bytes", bytes); |
| 79 | else if (bytes < 1ull << 20) snprintf(out, sizeof(out), "%.1f KiB", (float)bytes / 1024); |
| 80 | else if (bytes < 1ull << 30) snprintf(out, sizeof(out), "%.1f MiB", (float)bytes / 1024 / 1024); |
| 81 | else if (bytes < 1ull << 40) snprintf(out, sizeof(out), "%.1f GiB", (float)bytes / 1024 / 1024 / 1024); |
| 82 | else snprintf(out, sizeof(out), "%.1f TiB", (float)bytes / 1024 / 1024 / 1024 / 1024); |
| 83 | |
| 84 | return out; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | Format a number with separators per locale |
nothing calls this directly
no outgoing calls
no test coverage detected