blob: 1322602864a8e06f43959eff0a00d4974dc7611f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <boost/io/ios_state.hpp>
#include <iomanip>
#include <iostream>
#include "escape-char.hh"
namespace nix {
std::ostream & operator<<(std::ostream & s, MaybeHexEscapedChar c)
{
boost::io::ios_flags_saver _ifs(s);
if (isprint(c.c)) {
s << static_cast<char>(c.c);
} else {
s << "\\x" << std::hex << std::setfill('0') << std::setw(2)
<< (static_cast<unsigned int>(c.c) & 0xff);
}
return s;
}
} // namespace nix
|