aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/escape-char.cc
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-03-22 16:41:42 -0700
committerRebecca Turner <rbt@sent.as>2024-03-28 15:54:12 -0700
commit5ec2efb68677ccb5fd91c295cf6ae6039652ac73 (patch)
tree823e80abd2705e2ecadca7557240f917c6982b28 /src/libutil/escape-char.cc
parent62332c12505adc033eca7355de2b8a469355664f (diff)
Move `DebugChar` into its own file
Change-Id: Ia40549e5d0b78ece8dd0722c3a5a032b9915f24b
Diffstat (limited to 'src/libutil/escape-char.cc')
-rw-r--r--src/libutil/escape-char.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libutil/escape-char.cc b/src/libutil/escape-char.cc
new file mode 100644
index 000000000..132260286
--- /dev/null
+++ b/src/libutil/escape-char.cc
@@ -0,0 +1,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