2023-04-16 11:10:45 +00:00
|
|
|
#include "print.hh"
|
2023-04-09 20:42:20 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::ostream &
|
2023-04-16 10:56:31 +00:00
|
|
|
printLiteralString(std::ostream & str, const std::string_view string)
|
2023-04-15 18:56:51 +00:00
|
|
|
{
|
2023-04-09 20:42:20 +00:00
|
|
|
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 &
|
2023-04-16 10:56:31 +00:00
|
|
|
printLiteralBool(std::ostream & str, bool boolean)
|
2023-04-15 18:56:51 +00:00
|
|
|
{
|
2023-04-09 20:42:20 +00:00
|
|
|
str << (boolean ? "true" : "false");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|