blob: 28c6c8d6430838815cdc4ea0ac556694ef8ad7fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#pragma once
#include <limits>
#include <ostream>
namespace nix {
/**
* Escape a string for output.
*
* With default optional parameters, the output string will round-trip through
* the Nix evaluator (i.e. you can copy/paste this function's output into the
* REPL and have it evaluate as the string that got passed in).
*
* With non-default optional parameters, the output string will be
* human-readable.
*/
std::ostream & escapeString(
std::ostream & output,
const std::string_view string,
size_t maxLength = std::numeric_limits<size_t>::max(),
bool ansiColors = false
);
/**
* Escape a string for output, writing the escaped result to a new string.
*/
inline std::ostream & escapeString(std::ostream & output, const char * string)
{
return escapeString(output, std::string_view(string));
}
} // namespace nix
|