31 lines
930 B
C++
31 lines
930 B
C++
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utils.hpp>
|
|
|
|
namespace utils {
|
|
|
|
/* pads given string to length */
|
|
std::string pad(std::string s, const uint8_t len, const just j) {
|
|
if (len > s.size())
|
|
s.insert(j == left ? s.end() : s.begin(), len - s.size(), fill_char);
|
|
return s;
|
|
}
|
|
|
|
/* returns the string centered within given length */
|
|
std::string center(std::string str, const uint8_t len) {
|
|
const uint8_t padding = len - str.size();
|
|
str.insert(str.begin(), padding / 2, fill_char);
|
|
str.insert(str.end(), padding / 2, fill_char);
|
|
return str;
|
|
}
|
|
|
|
/* finds first dir in path and returns it. don't refactor, you don't understand it, its fast enough, and you only use it on init */
|
|
std::string getFirstDir(const std::string_view& path) {
|
|
for (const auto& entry : std::filesystem::directory_iterator(path))
|
|
return entry.path();
|
|
return "";
|
|
}
|
|
|
|
} |