aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/print.cc
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-04-16 13:10:45 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-04-16 13:10:45 +0200
commit28a5cdde02964306e7eb443f696c8d5d59ebf9e9 (patch)
tree413a587bbf5d2666cebbab41432d202c5f1fac9c /src/libexpr/print.cc
parent1e2dd669bcdd8df6cdaac061e035828626906447 (diff)
libexpr/value/print.* -> libexpr/print.*
Generalizes the file to sensibly allow printing any part of the language syntax.
Diffstat (limited to 'src/libexpr/print.cc')
-rw-r--r--src/libexpr/print.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc
new file mode 100644
index 000000000..282903b72
--- /dev/null
+++ b/src/libexpr/print.cc
@@ -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;
+}
+
+}