From 62d929171c30d48250ad6bfc0a7530aeda4d660f Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 5 Mar 2023 17:06:07 -0500 Subject: [PATCH] fromBytes --- include/blt/std/format.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/blt/std/format.h b/include/blt/std/format.h index 51e5dd8..6ae79cf 100644 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -12,6 +12,21 @@ #include namespace blt::string { + static inline std::string fromBytes(unsigned long bytes){ + if (bytes > 1073741824) { + // gigabyte + return std::to_string((double)bytes / 1024.0 / 1024.0 / 1024.0) += "gb"; + } else if (bytes > 1048576) { + // megabyte + return std::to_string((double)bytes / 1024.0 / 1024.0) += "mb"; + } else if (bytes > 1024) { + // kilobyte + return std::to_string((double)bytes / 1024.0) += "kb"; + } else { + return std::to_string(bytes) += "b"; + } + } + // TODO template the padding functions: /**