31 unsigned indentAmount;
33 std::stringstream buffer;
34 const std::string nl =
"\n";
40 void increaseIndent() { indentLevel += indentAmount; }
41 void decreaseIndent() {
42 indentLevel -= indentAmount;
43 if (indentLevel < 0) BUG(
"Negative indent");
50 if (!endsInSpace) buffer <<
" ";
54 void append(
cstring str) { append(str.c_str()); }
59 void append(
const std::string &str) {
60 if (str.empty())
return;
61 endsInSpace = ::isspace(str.at(str.size() - 1));
65 endsInSpace = ::isspace(c);
68 void append(
const char *str) {
69 if (str ==
nullptr) BUG(
"Null argument to append");
70 if (strlen(str) == 0)
return;
71 endsInSpace = ::isspace(str[strlen(str) - 1]);
74 void appendFormat(
const char *format, ...) {
77 cstring str = Util::vprintf_format(format, ap);
81 void append(
unsigned u) { appendFormat(
"%d", u); }
82 void append(
int u) { appendFormat(
"%d", u); }
84 void endOfStatement(
bool addNl =
false) {
96 buffer << std::string(indentLevel,
' ');
97 if (indentLevel > 0) endsInSpace =
true;
100 void blockEnd(
bool nl) {
107 std::string toString()
const {
return buffer.str(); }
108 void commentStart() { append(
"/* "); }
109 void commentEnd() { append(
" */"); }
110 bool lastIsSpace()
const {
return endsInSpace; }