From 47c45e8d9e95c4834a5061cd9fae8251d62d063d Mon Sep 17 00:00:00 2001 From: Drath Vader Date: Thu, 27 Nov 2025 20:20:59 +0100 Subject: [PATCH] more readable this way --- include/utils.hpp | 7 ++++++- src/utils.cpp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/utils.hpp b/include/utils.hpp index f7d830b..db9ca66 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -10,10 +10,15 @@ // wrapper around readFile2 func so we can avoid readFile and reuse one buffer, this should be faster and less bug prone? #define fastReadNum(path, val) readFile2(path, buf, sizeof(buf)); val = strtoll(buf, NULL, 10) +enum JUST { + RIGHT, + LEFT +}; + // pretty prints num with given decs, 0 by default. its basically a macro so we inline it inline std::string pNum(auto num, uint8_t decs = 0) { return std::format("{:.{}f}", num, decs); } -std::string pad(std::string s, uint8_t len, bool ljust = false); +std::string pad(std::string s, uint8_t len, JUST j = JUST::RIGHT); std::string center(std::string str, uint8_t len); std::string pBytes(double bytes, bool isKbytes = false); std::string readFile(std::string path, size_t trim = 4096); diff --git a/src/utils.cpp b/src/utils.cpp index f9cf0d7..310e6ee 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -13,9 +13,9 @@ #include // pads given string to length -std::string pad(std::string s, uint8_t len, bool ljust) { +std::string pad(std::string s, uint8_t len, JUST j) { if (len > s.size()) - s.insert(ljust ? s.end() : s.begin(), len - s.size(), FILL_CHAR); + s.insert(j == JUST::LEFT ? s.end() : s.begin(), len - s.size(), FILL_CHAR); return s; }