utils: update date/size parsing, factor out format

And update tests
This commit is contained in:
Dirk-Jan C. Binnema
2022-04-28 22:49:45 +03:00
parent 4b9c663ded
commit b7a30c0a36
6 changed files with 284 additions and 165 deletions

View File

@ -22,6 +22,7 @@
#include <xapian.h>
#include <glib.h>
#include "mu-result.hh"
namespace Mu {
@ -60,6 +61,25 @@ try {
return static_cast<Default>(def);
}
template <typename Func>
auto
xapian_try_result(Func&& func) noexcept -> std::decay_t<decltype(func())>
try {
return func();
} catch (const Xapian::Error& xerr) {
return Err(Error::Code::Xapian, "%s", xerr.get_error_string());
} catch (const std::runtime_error& re) {
return Err(Error::Code::Internal, "runtime error: %s", re.what());
} catch (const std::exception& e) {
return Err(Error::Code::Internal, "caught exception: %s", e.what());
} catch (...) {
return Err(Error::Code::Internal, "caught exception");
}
} // namespace Mu
#endif /* MU_ XAPIAN_UTILS_HH__ */