jay/shared/utils.cpp
2025-03-28 23:12:34 +02:00

33 lines
946 B
C++

#include "utils.h"
std::string Shared::getISOTimestamp() {
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> time = std::chrono::floor<std::chrono::seconds>(now);
return std::format("{:%FT%TZ}", time);
}
std::string Shared::getUUID() {
uuid_t uuid;
uuid_generate_random(uuid);
char uuid_str[37];
uuid_unparse_lower(uuid, uuid_str);
return std::string(uuid_str);
}
Shared::Strings Shared::split(const std::string& string, const std::string& delimiter) {
Strings result;
std::size_t last = 0;
std::size_t next = string.find(delimiter, last);
while (next != std::string::npos) {
result.emplace_back(string.substr(last, next - last));
last = next + 1;
next = string.find(delimiter, last);
}
result.emplace_back(string.substr(last));
return result;
}