1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 12:41:15 +02:00

libexpr/value/print.* -> libexpr/print.*

Generalizes the file to sensibly allow printing any part of the
language syntax.
This commit is contained in:
Robert Hensing 2023-04-16 13:10:45 +02:00
parent 1e2dd669bc
commit 28a5cdde02
5 changed files with 4 additions and 4 deletions

28
src/libexpr/print.cc Normal file
View file

@ -0,0 +1,28 @@
#include "print.hh"
namespace nix {
std::ostream &
printLiteralString(std::ostream & str, const std::string_view string)
{
str << "\"";
for (auto i = string.begin(); i != string.end(); ++i) {
if (*i == '\"' || *i == '\\') str << "\\" << *i;
else if (*i == '\n') str << "\\n";
else if (*i == '\r') str << "\\r";
else if (*i == '\t') str << "\\t";
else if (*i == '$' && *(i+1) == '{') str << "\\" << *i;
else str << *i;
}
str << "\"";
return str;
}
std::ostream &
printLiteralBool(std::ostream & str, bool boolean)
{
str << (boolean ? "true" : "false");
return str;
}
}