Skip to content

Commit

Permalink
src: simplify Reindent function in json_utils.cc
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
sapics authored and codebytere committed Jun 18, 2020
1 parent cdcd768 commit 1f996b7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/json_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down

0 comments on commit 1f996b7

Please sign in to comment.