refactor utils
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
#define FILL_CHAR ' '
|
||||
namespace utils {
|
||||
|
||||
enum JUST { RIGHT, LEFT };
|
||||
const char FILL_CHAR = ' ';
|
||||
|
||||
std::string pad(std::string s, uint8_t len, JUST j = JUST::RIGHT);
|
||||
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(std::string path, char* buffer, size_t maxlen);
|
||||
@@ -22,9 +26,14 @@ inline long long fastReadNum(const std::string& path, char (&buf)[N]) {
|
||||
return std::strtoll(buf, nullptr, 10);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
inline bool fileExists(std::string_view path) {
|
||||
return std::filesystem::exists(path);
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user