forked from lix-project/lix
Support control characters in JSON output
This commit is contained in:
parent
f77be20c16
commit
d61853430a
|
@ -3,6 +3,7 @@
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -16,6 +17,8 @@ void escapeJSON(std::ostream & str, const string & s)
|
||||||
else if (*i == '\n') str << "\\n";
|
else if (*i == '\n') str << "\\n";
|
||||||
else if (*i == '\r') str << "\\r";
|
else if (*i == '\r') str << "\\r";
|
||||||
else if (*i == '\t') str << "\\t";
|
else if (*i == '\t') str << "\\t";
|
||||||
|
else if (*i >= 0 && *i < 32)
|
||||||
|
str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) *i << std::dec;
|
||||||
else str << *i;
|
else str << *i;
|
||||||
str << "\"";
|
str << "\"";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ struct JSONObject
|
||||||
attr(s);
|
attr(s);
|
||||||
escapeJSON(str, t);
|
escapeJSON(str, t);
|
||||||
}
|
}
|
||||||
|
void attr(const string & s, int n)
|
||||||
|
{
|
||||||
|
attr(s);
|
||||||
|
str << n;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JSONList
|
struct JSONList
|
||||||
|
|
Loading…
Reference in a new issue