blob: 8b878aef65ba6e09a51107e9b85db70df88699bd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "indent_text.h"
#include <util/stream/str.h>
TString IndentText(TStringBuf text, TStringBuf indent) {
if (text.empty())
return TString();
TStringStream ss;
ss.Reserve(text.size() + 20);
char pc = 0;
for (size_t i = 0; i < text.size(); ++i) {
if (i == 0 || pc == '\n')
ss << indent;
char c = text.at(i);
ss << c;
pc = c;
}
if (pc != '\n')
ss << '\n';
return ss.Str();
}
|