From 6edd4cb9eaca78a5c4254265f27602e7055d7e44 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Nov 2023 21:19:43 +0100 Subject: a --- compat/debug.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'compat/debug.cpp') diff --git a/compat/debug.cpp b/compat/debug.cpp index e3efaf5c..a3c2ba25 100644 --- a/compat/debug.cpp +++ b/compat/debug.cpp @@ -1,8 +1,22 @@ #include "debug.hpp" #include "compat/strerror.hpp" +#include +#include + +// Error{} << "error" << colon() << "can't open file" << colon() << quoted("foo") << error_string(EINVAL); +// ===> "error: can't open file 'foo': Invalid argument" namespace floormat::detail::corrade_debug { +Debug& operator<<(Debug& dbg, Colon) +{ + auto flags = dbg.flags(); + dbg.setFlags(flags | Debug::Flag::NoSpace); + dbg << ":"; + dbg.setFlags(flags); + return dbg; +} + Debug& operator<<(Debug& dbg, ErrorString box) { auto flags = dbg.flags(); @@ -14,9 +28,7 @@ Debug& operator<<(Debug& dbg, ErrorString box) return dbg; } -template struct Quoted; - -Debug::Flags debug1(Debug& dbg, char c) +Debug::Flags quoted_begin(Debug& dbg, char c) { auto flags = dbg.flags(); dbg << ""; @@ -26,7 +38,7 @@ Debug::Flags debug1(Debug& dbg, char c) return flags; } -Debug& debug2(Debug& dbg, Debug::Flags flags, char c) +Debug& quoted_end(Debug& dbg, Debug::Flags flags, char c) { char buf[2] { c, '\0' }; dbg << buf; @@ -34,10 +46,16 @@ Debug& debug2(Debug& dbg, Debug::Flags flags, char c) return dbg; } +template struct Quoted; + } // namespace floormat::detail::corrade_debug namespace floormat { -floormat::detail::corrade_debug::ErrorString error_string(int error) { return { error }; } +using namespace floormat::detail::corrade_debug; + +Colon colon() { return Colon{}; } +ErrorString error_string(int error) { return { error }; } +ErrorString error_string() { return { errno }; } } // namespace floormat -- cgit v1.2.3