#ifndef UTILS_HPP #define UTILS_HPP #include #include #include #include #include namespace utils { constexpr char fill_char = ' '; enum just { right, left }; 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); ssize_t readFile(const std::string& path, char* buffer, size_t maxlen); ssize_t readFile(const char* path, char* buffer, size_t maxlen); std::string getFirstDir(const std::string_view& path); /* reads a number fast and divides it if needed */ template inline void fastReadNum(const std::string& path, char (&buf)[N], T& result) { readFile(path, buf, N); if constexpr (Divider == 1) { std::from_chars(buf, buf + N, result); return; } uint64_t temp{}; std::from_chars(buf, buf + N, temp); if constexpr (std::is_floating_point_v) result = temp / static_cast(Divider); else result = static_cast(temp / Divider); } inline std::string pNum(const auto num, const uint8_t decs = 0) { return std::format("{:.{}f}", num, decs); } inline bool fileExists(const std::string_view& path) { return std::filesystem::exists(path); } } // namespace utils #endif