diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 21:57:46 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 21:57:46 +1100 |
| commit | e4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch) | |
| tree | ed58c3c246e3af1af337697695d780aa31f6ad9a /src/shared/shared.cc | |
| parent | 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff) | |
Update to most recent version (old initial commit)
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 |
