diff options
Diffstat (limited to 'src/shared/shared.cc')
| -rw-r--r-- | src/shared/shared.cc | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/shared/shared.cc b/src/shared/shared.cc index 55ccf1f..f5a478b 100644 --- a/src/shared/shared.cc +++ b/src/shared/shared.cc @@ -2,6 +2,12 @@ namespace shared { +float get_duration_seconds(const time_duration_t& duration) noexcept { + const auto fdiff = + std::chrono::duration_cast<std::chrono::duration<float>>(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); }); @@ -26,7 +32,7 @@ std::ofstream open_file(const std::string& dir, return ret; } -void compress_string(std::string& str) noexcept { +std::string compress_string(const std::string& str) { std::stringstream input(str); boost::iostreams::filtering_streambuf<boost::iostreams::input> out; @@ -37,21 +43,26 @@ void compress_string(std::string& str) noexcept { std::stringstream result; boost::iostreams::copy(out, result); - str = result.str(); + return result.str(); } -void decompress_string(std::string& str) noexcept { - std::stringstream input; - input << str; +std::optional<std::string> +maybe_decompress_string(const std::string& str) noexcept { + try { + std::stringstream input; + input << str; - boost::iostreams::filtering_streambuf<boost::iostreams::input> in; - in.push(boost::iostreams::gzip_decompressor()); - in.push(input); + boost::iostreams::filtering_streambuf<boost::iostreams::input> in; + in.push(boost::iostreams::gzip_decompressor()); + in.push(input); - std::stringstream result; - boost::iostreams::copy(in, result); + std::stringstream result; + boost::iostreams::copy(in, result); - str = result.str(); + return result.str(); + } catch (...) { + return std::nullopt; + } } } // namespace shared |
