Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-03-29 21:11:56 +0300
committerMichaƫl Zasso <targos@protonmail.com>2020-04-11 11:03:12 +0300
commitf284d599bb8b1ecd0a11e5d1c4354d5f4c69f69f (patch)
tree1d11a0139ef52d8a17e0a4963732a59eccc355d6 /src/node_report_utils.cc
parente066584d94e7fbe81cf4978c517446fca6b00bbc (diff)
src: move JSONWriter into its own file
The JSONWriter feature is not inherently related to the report feature in any way. As a drive-by fix, remove a number of unused header includes. PR-URL: https://github.com/nodejs/node/pull/32552 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'src/node_report_utils.cc')
-rw-r--r--src/node_report_utils.cc64
1 files changed, 2 insertions, 62 deletions
diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc
index efa15790b9b..abbf6d529d0 100644
--- a/src/node_report_utils.cc
+++ b/src/node_report_utils.cc
@@ -1,9 +1,11 @@
+#include "json_utils.h"
#include "node_internals.h"
#include "node_report.h"
#include "util-inl.h"
namespace report {
+using node::JSONWriter;
using node::MallocedBuffer;
static constexpr auto null = JSONWriter::Null{};
@@ -225,66 +227,4 @@ void WalkHandle(uv_handle_t* h, void* arg) {
writer->json_end();
}
-std::string EscapeJsonChars(const std::string& str) {
- const std::string control_symbols[0x20] = {
- "\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005",
- "\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r",
- "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013",
- "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019",
- "\\u001a", "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f"
- };
-
- std::string ret;
- size_t last_pos = 0;
- size_t pos = 0;
- for (; pos < str.size(); ++pos) {
- std::string replace;
- char ch = str[pos];
- if (ch == '\\') {
- replace = "\\\\";
- } else if (ch == '\"') {
- replace = "\\\"";
- } else {
- size_t num = static_cast<size_t>(ch);
- if (num < 0x20) replace = control_symbols[num];
- }
- if (!replace.empty()) {
- if (pos > last_pos) {
- ret += str.substr(last_pos, pos - last_pos);
- }
- last_pos = pos + 1;
- ret += replace;
- }
- }
- // Append any remaining symbols.
- if (last_pos < str.size()) {
- ret += str.substr(last_pos, pos - last_pos);
- }
- return ret;
-}
-
-std::string Reindent(const std::string& str, int indent_depth) {
- std::string indent;
- for (int i = 0; i < indent_depth; i++) indent += ' ';
-
- std::string out;
- std::string::size_type pos = 0;
- do {
- std::string::size_type prev_pos = pos;
- pos = str.find('\n', pos);
-
- out.append(indent);
-
- if (pos == std::string::npos) {
- out.append(str, prev_pos, std::string::npos);
- break;
- } else {
- pos++;
- out.append(str, prev_pos, pos - prev_pos);
- }
- } while (true);
-
- return out;
-}
-
} // namespace report