Skip to content

Commit e07c1c2

Browse files
sapicscodebytere
authored andcommitted
src: simplify Reindent function in json_utils.cc
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]>
1 parent 449d9ec commit e07c1c2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/json_utils.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ std::string EscapeJsonChars(const std::string& str) {
4141
}
4242

4343
std::string Reindent(const std::string& str, int indent_depth) {
44-
std::string indent;
45-
for (int i = 0; i < indent_depth; i++) indent += ' ';
46-
44+
if (indent_depth <= 0) return str;
45+
const std::string indent(indent_depth, ' ');
4746
std::string out;
4847
std::string::size_type pos = 0;
49-
do {
48+
for (;;) {
5049
std::string::size_type prev_pos = pos;
5150
pos = str.find('\n', pos);
5251

@@ -59,7 +58,7 @@ std::string Reindent(const std::string& str, int indent_depth) {
5958
pos++;
6059
out.append(str, prev_pos, pos - prev_pos);
6160
}
62-
} while (true);
61+
}
6362

6463
return out;
6564
}

0 commit comments

Comments
 (0)