[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
233/376: Support control characters in JSON output
From: |
Ludovic Courtès |
Subject: |
233/376: Support control characters in JSON output |
Date: |
Wed, 28 Jan 2015 22:05:17 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit d61853430a3df8914995ae35ac7a0795827d7a87
Author: Eelco Dolstra <address@hidden>
Date: Tue Sep 30 00:41:18 2014 +0200
Support control characters in JSON output
---
src/libexpr/value-to-json.cc | 3 +++
src/libexpr/value-to-json.hh | 5 +++++
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index a2004df..d1ec9b5 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -3,6 +3,7 @@
#include "util.hh"
#include <cstdlib>
+#include <iomanip>
namespace nix {
@@ -16,6 +17,8 @@ void escapeJSON(std::ostream & str, const string & s)
else if (*i == '\n') str << "\\n";
else if (*i == '\r') str << "\\r";
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;
str << "\"";
}
diff --git a/src/libexpr/value-to-json.hh b/src/libexpr/value-to-json.hh
index e3a97ef..f6796f2 100644
--- a/src/libexpr/value-to-json.hh
+++ b/src/libexpr/value-to-json.hh
@@ -36,6 +36,11 @@ struct JSONObject
attr(s);
escapeJSON(str, t);
}
+ void attr(const string & s, int n)
+ {
+ attr(s);
+ str << n;
+ }
};
struct JSONList
- 228/376: Fix use of PAGER during tests, (continued)
- 228/376: Fix use of PAGER during tests, Ludovic Courtès, 2015/01/28
- 221/376: Remove release notes Hydra product, Ludovic Courtès, 2015/01/28
- 218/376: Make forceValueDeep work on values with cycles, Ludovic Courtès, 2015/01/28
- 229/376: Remove bash requirement, Ludovic Courtès, 2015/01/28
- 231/376: nix-daemon: Close unnecessary fd, Ludovic Courtès, 2015/01/28
- 230/376: Bindings: Remove copy constructor, Ludovic Courtès, 2015/01/28
- 222/376: Add missing static, Ludovic Courtès, 2015/01/28
- 223/376: manual: add a note that lists are strict in length, Ludovic Courtès, 2015/01/28
- 232/376: printMissing(): Print derivations in approximate build order, Ludovic Courtès, 2015/01/28
- 234/376: printValue(): Don't print <CYCLE> for repeated values, Ludovic Courtès, 2015/01/28
- 233/376: Support control characters in JSON output,
Ludovic Courtès <=
- 235/376: createDirs(): Handle ‘path’ being a symlink, Ludovic Courtès, 2015/01/28
- 238/376: Add test for readDir primop, Ludovic Courtès, 2015/01/28
- 240/376: Remove some duplicate code, Ludovic Courtès, 2015/01/28
- 239/376: Add readDir primop, Ludovic Courtès, 2015/01/28
- 224/376: add manpage for nix-generate-patches, Ludovic Courtès, 2015/01/28
- 246/376: Typo, Ludovic Courtès, 2015/01/28
- 245/376: Get rid of some unnecessary ExprConcatStrings nodes in dynamic attrs, Ludovic Courtès, 2015/01/28
- 243/376: Add primop ‘catAttrs’, Ludovic Courtès, 2015/01/28
- 249/376: nix-copy-closure: Use strict, Ludovic Courtès, 2015/01/28
- 241/376: Tweak, Ludovic Courtès, 2015/01/28