#include "shared.hh" namespace shared { float get_duration_seconds(const time_duration_t& duration) noexcept { const auto fdiff = std::chrono::duration_cast>(duration); return fdiff.count(); } std::string make_string_lower(std::string str) noexcept { std::ranges::transform(str.begin(), str.end(), str.begin(), [](const auto c) { return std::tolower(c); }); return str; } std::string read_file(const std::string& path) { std::ifstream input(path); if (!input.is_open()) { throw std::runtime_error("failed to read file: " + path); } return std::string{std::istreambuf_iterator(input), std::istreambuf_iterator()}; } std::ofstream open_file(const std::string& dir, const std::ios_base::openmode mode) { std::ofstream ret(dir, mode); if (!ret.is_open()) { throw std::runtime_error("failed to write file: " + dir); } return ret; } std::string compress_string(const std::string& str) { std::stringstream input(str); boost::iostreams::filtering_streambuf out; out.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params( boost::iostreams::gzip::best_compression))); out.push(input); std::stringstream result; boost::iostreams::copy(out, result); return result.str(); } std::optional maybe_decompress_string(const std::string& str) noexcept { try { std::stringstream input; input << str; boost::iostreams::filtering_streambuf in; in.push(boost::iostreams::gzip_decompressor()); in.push(input); std::stringstream result; boost::iostreams::copy(in, result); return result.str(); } catch (...) { return std::nullopt; } } } // namespace shared