src: simplify Reindent function in json_utils.cc

PR-URL: https://github.com/nodejs/node/pull/33722
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
sapics authored and Shelley Vohr committed 2020-06-30 09:34:06 -07:00
1 parent de48495222
commit c7e2ec11ab
1 file changed
+4 -5
+4 -5
View File
@@ -41,12 +41,11 @@ std::string EscapeJsonChars(const std::string& str) {
}
std::string Reindent(const std::string& str, int indent_depth) {
std::string indent;
for (int i = 0; i < indent_depth; i++) indent += ' ';
if (indent_depth <= 0) return str;
const std::string indent(indent_depth, ' ');
std::string out;
std::string::size_type pos = 0;
do {
for (;;) {
std::string::size_type prev_pos = pos;
pos = str.find('\n', pos);
@@ -59,7 +58,7 @@ std::string Reindent(const std::string& str, int indent_depth) {
pos++;
out.append(str, prev_pos, pos - prev_pos);
}
} while (true);
}
return out;
}