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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
  • 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.