nestlog: + quoted_char inserter
This commit is contained in:
parent
d46c734950
commit
7b233acf29
1 changed files with 43 additions and 0 deletions
43
include/nestlog/quoted_char.hpp
Normal file
43
include/nestlog/quoted_char.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* @file quoted_char.hpp */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
template<typename CharT>
|
||||
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<typename CharT>
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os, quoted_char<CharT> const & x) {
|
||||
x.print(os);
|
||||
return os;
|
||||
} /*operator<<*/
|
||||
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end quoted_char.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue