diff --git a/include/utils.hpp b/include/utils.hpp index a743659..a25d759 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -20,6 +20,7 @@ std::string pNum(double num, uint8_t decs = 0); std::string pNum(float num, uint8_t decs = 0); std::string pad(std::string s, uint8_t len, bool ljust = false); +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); ssize_t readFile2(std::string path, char *buffer, size_t maxlen); diff --git a/src/utils.cpp b/src/utils.cpp index c901c21..4787885 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -18,6 +18,13 @@ std::string pad(std::string s, uint8_t len, bool ljust) { return s; } +// returns the string centered within given length +std::string center(std::string str, uint8_t len) { + uint8_t padding = len - str.size(); + str.insert(str.begin(), padding / 2, FILL_CHAR); + str.insert(str.end(), padding / 2, FILL_CHAR); + return str; +} // converts large number in (k)bytes to human readable numer with suffix and sane decimal std::string pBytes(double bytes, bool isKbytes) { @@ -77,4 +84,3 @@ std::string getFirstDir(std::string path) { return entry.path(); return ""; } -