Files
linuxSmartie/include/utils.hpp

31 lines
863 B
C++

#ifndef UTILS_HPP
#define UTILS_HPP
#include <cstdint>
#include <format>
#include <string>
#define 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(std::string path, char* buffer, size_t maxlen);
ssize_t readFile(const char* path, char* buffer, size_t maxlen);
std::string getFirstDir(std::string_view path);
template <size_t N>
inline long long fastReadNum(const std::string& path, char (&buf)[N]) {
readFile(path, 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);
}
#endif