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:
authorsapics <gv.nishino@gmail.com>2020-06-04 10:08:43 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2020-06-08 15:01:54 +0300
commit689680a5315a51cfe347968a893c38bb60be56eb (patch)
tree76944ccde7bed143cf3364c2b31fe51a2aa47aae /src/json_utils.cc
parent813368c0371977b58f7781734c66b564fe9f92b4 (diff)
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>
Diffstat (limited to 'src/json_utils.cc')
-rw-r--r--src/json_utils.cc9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/json_utils.cc b/src/json_utils.cc
index aa03a6d7305..96f178cf351 100644
--- a/src/json_utils.cc
+++ b/src/json_utils.cc
@@ -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;
}