31 unsigned indentAmount;
35 bool supressSemi =
false;
40 void increaseIndent() { indentLevel += indentAmount; }
41 void decreaseIndent() {
42 indentLevel -= indentAmount;
43 if (indentLevel < 0) BUG(
"Negative indent");
50 if (!endsInSpace) buffer.Append(
" ");
54 void append(
cstring str) { append(str.c_str()); }
55 void appendLine(
const char *str) {
63 void append(
const std::string &str) {
64 if (str.empty())
return;
65 endsInSpace = ::isspace(str.back());
68 [[deprecated(
"use string / char* version instead")]]
70 std::string str(1, c);
73 void append(
const char *str) {
74 if (str ==
nullptr) BUG(
"Null argument to append");
75 if (strlen(str) == 0)
return;
76 endsInSpace = ::isspace(str[strlen(str) - 1]);
80 template <
typename... Args>
81 void appendFormat(
const absl::FormatSpec<Args...> &format, Args &&...args) {
83 append(absl::StrFormat(format, std::forward<Args>(args)...));
85 void append(
unsigned u) { appendFormat(
"%d", u); }
86 void append(
int u) { appendFormat(
"%d", u); }
88 void endOfStatement(
bool addNl =
false) {
89 if (!supressSemi) append(
";");
93 void supressStatementSemi() { supressSemi =
true; }
102 buffer.Append(std::string(indentLevel,
' '));
103 if (indentLevel > 0) endsInSpace =
true;
106 void blockEnd(
bool nl) {
113 std::string toString()
const {
return std::string(buffer); }
114 void commentStart() { append(
"/* "); }
115 void commentEnd() { append(
" */"); }
116 bool lastIsSpace()
const {
return endsInSpace; }