42 lines
997 B
C++
42 lines
997 B
C++
#ifndef UTILS_HPP
|
|
#define UTILS_HPP
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <format>
|
|
#include <string>
|
|
|
|
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);
|
|
|
|
template <size_t N>
|
|
inline int fastReadNum(const std::string& path, char (&buf)[N]) {
|
|
readFile(path, buf, N);
|
|
int ret = 0;
|
|
std::from_chars(buf, buf + N, ret);
|
|
return ret;
|
|
}
|
|
|
|
inline std::string pNum(auto num, 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
|