libcmo21/CodeGen/CKIndentHelper.java
2023-08-18 15:55:31 +08:00

48 lines
912 B
Java

import java.io.OutputStreamWriter;
public class CKIndentHelper {
public CKIndentHelper(OutputStreamWriter writer) {
mIndent = 0;
}
private int mIndent;
private OutputStreamWriter mWriter;
public void inc() {
++mIndent;
}
public void dec() {
--mIndent;
}
public void indent() throws Exception {
mWriter.write("\n");
for (int i = 0; i < mIndent; ++i) {
mWriter.write("\t");
}
}
public void puts(String data) throws Exception {
indent();
mWriter.write(data);
}
public void printf(String fmt, Object... args) throws Exception {
indent();
mWriter.write(String.format(fmt, args));
}
public void briefComment(String fmt) throws Exception {
if (fmt == null) return;
printf("/**< {} */", fmt.replaceAll("[\\r\\n]+", ""));
}
public void afterMemberComment(String fmt) throws Exception {
if (fmt == null) return;
mWriter.write("\t");
mWriter.write(fmt);
}
}