bunch of shit clang-tidy and clion made me do

This commit is contained in:
2026-01-01 16:36:15 +01:00
parent 6f8e2e2abd
commit f871dbd2e8
9 changed files with 57 additions and 55 deletions

View File

@@ -3,7 +3,6 @@
#include <array>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <format>
#include <log.hpp>
@@ -14,24 +13,23 @@
namespace utils {
/* pads given string to length */
std::string pad(std::string s, uint8_t len, just j) {
std::string pad(std::string s, const uint8_t len, just j) {
if (len > s.size())
s.insert(j == just::left ? s.end() : s.begin(), len - s.size(), FILL_CHAR);
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, uint8_t len) {
uint8_t padding = len - str.size();
str.insert(str.begin(), padding / 2, FILL_CHAR);
str.insert(str.end(), padding / 2, FILL_CHAR);
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;
}
/* converts large number in (k)bytes to human readable numer with suffix and sane decimal */
std::string pBytes(double bytes, bool isKbytes) {
std::array suffix_list = {'K', 'M', 'G', 'T', 'P', 'E', 'Z'};
for (auto& suffix : suffix_list) {
/* converts large number in (k)bytes to human-readable numer with suffix and sane decimal */
std::string pBytes(double bytes, const bool isKbytes) {
for (constexpr std::array suffix_list = {'K', 'M', 'G', 'T', 'P', 'E', 'Z'}; const auto& suffix : suffix_list) {
if (suffix == 'K' && isKbytes) continue; // skip first loop if already in Kbytes
bytes /= 1024.0;
if (bytes < 1024) {
@@ -45,24 +43,24 @@ std::string pBytes(double bytes, bool isKbytes) {
/* reads maxlen of chars of the file in path into buffer */
ssize_t readFile(const char* path, char* buffer, size_t maxlen) {
int fd = open(path, O_RDONLY | O_CLOEXEC);
const int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
applog(LOG::ERR, "Error reading {}", path);
return 0;
}
ssize_t len = read(fd, buffer, maxlen - 1);
const ssize_t len = read(fd, buffer, maxlen - 1);
if (len >= 0) buffer[len] = '\0';
close(fd);
return len;
}
/* overload so it takes std::string as path */
ssize_t readFile(const std::string path, char* buffer, size_t maxlen) {
ssize_t readFile(const std::string& path, char* buffer, size_t maxlen) {
return readFile(path.c_str(), buffer, maxlen);
}
/* finds first dir in path and returns it. dont refactor, you dont understand it, its fast enough and you only use it on init */
std::string getFirstDir(std::string_view path) {
/* 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 "";