diff options
author | Rebecca Turner <rbt@sent.as> | 2024-03-22 16:41:42 -0700 |
---|---|---|
committer | Rebecca Turner <rbt@sent.as> | 2024-03-28 15:54:12 -0700 |
commit | 5ec2efb68677ccb5fd91c295cf6ae6039652ac73 (patch) | |
tree | 823e80abd2705e2ecadca7557240f917c6982b28 /src/libutil/escape-char.hh | |
parent | 62332c12505adc033eca7355de2b8a469355664f (diff) |
Move `DebugChar` into its own file
Change-Id: Ia40549e5d0b78ece8dd0722c3a5a032b9915f24b
Diffstat (limited to 'src/libutil/escape-char.hh')
-rw-r--r-- | src/libutil/escape-char.hh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libutil/escape-char.hh b/src/libutil/escape-char.hh new file mode 100644 index 000000000..c7bae7ec0 --- /dev/null +++ b/src/libutil/escape-char.hh @@ -0,0 +1,22 @@ +#pragma once +#include <ostream> + +namespace nix { + +/** + * A struct that prints a debug representation of a character, like `\x1f` for + * non-printable characters, or the character itself for other characters. + * + * Note that these are suitable for human readable output, but further care is + * necessary to include them in C++ strings to avoid running into adjacent + * hex-like characters. (`"puppy\x1bdoggy"` parses as `"puppy" "\x1bd" "oggy"` + * and errors because 0x1bd is too big for a `char`.) + */ +struct MaybeHexEscapedChar +{ + char c; +}; + +std::ostream & operator<<(std::ostream & s, MaybeHexEscapedChar c); + +} // namespace nix |