From 7b233acf2941e0ebe3a77768575a83ca92ba67c8 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 16 Sep 2023 14:22:07 -0400 Subject: [PATCH] nestlog: + quoted_char inserter --- include/nestlog/quoted_char.hpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/nestlog/quoted_char.hpp diff --git a/include/nestlog/quoted_char.hpp b/include/nestlog/quoted_char.hpp new file mode 100644 index 00000000..010eefa3 --- /dev/null +++ b/include/nestlog/quoted_char.hpp @@ -0,0 +1,43 @@ +/* @file quoted_char.hpp */ + +#pragma once + +#include + +namespace xo { + template + class quoted_char { + public: + quoted_char(CharT ch) : ch_{ch} {} + + void print(std::ostream & os) const { + switch(ch_) { + case '\033': + os << "\\033"; + break; + case '\n': + os << "\\n"; + break; + case '\r': + os << "\\r"; + break; + default: + os << ch_; + } + } + + private: + CharT ch_; + }; /*quoted_char*/ + + template + inline std::ostream & + operator<<(std::ostream & os, quoted_char const & x) { + x.print(os); + return os; + } /*operator<<*/ + +} /*namespace xo*/ + + +/* end quoted_char.hpp */