diff options
author | Adam Lesinski <adamlesinski@google.com> | 2014-08-15 14:47:28 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2014-08-25 20:04:07 -0700 |
commit | 1e466385d4a4f1acee080fa0fdf16cc8fd8ce7ca (patch) | |
tree | 431c15e17f780767289dc5d3362d5d6d53ee3c18 /tools/aapt/IndentPrinter.h | |
parent | 5b8e5a7d4c930b42e1a3c2b3e67144b89d37efa2 (diff) | |
download | frameworks_base-1e466385d4a4f1acee080fa0fdf16cc8fd8ce7ca.zip frameworks_base-1e466385d4a4f1acee080fa0fdf16cc8fd8ce7ca.tar.gz frameworks_base-1e466385d4a4f1acee080fa0fdf16cc8fd8ce7ca.tar.bz2 |
Have R classes generate their own reference rewrite logic
Change-Id: I0e5b8311fc3479d966a49f9acf0d4c32a6a024d3
Diffstat (limited to 'tools/aapt/IndentPrinter.h')
-rw-r--r-- | tools/aapt/IndentPrinter.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/aapt/IndentPrinter.h b/tools/aapt/IndentPrinter.h new file mode 100644 index 0000000..6fc94bc --- /dev/null +++ b/tools/aapt/IndentPrinter.h @@ -0,0 +1,63 @@ +#ifndef __INDENT_PRINTER_H +#define __INDENT_PRINTER_H + +class IndentPrinter { +public: + IndentPrinter(FILE* stream, int indentSize=2) + : mStream(stream) + , mIndentSize(indentSize) + , mIndent(0) + , mNeedsIndent(true) { + } + + void indent(int amount = 1) { + mIndent += amount; + if (mIndent < 0) { + mIndent = 0; + } + } + + void print(const char* fmt, ...) { + doIndent(); + va_list args; + va_start(args, fmt); + vfprintf(mStream, fmt, args); + va_end(args); + } + + void println(const char* fmt, ...) { + doIndent(); + va_list args; + va_start(args, fmt); + vfprintf(mStream, fmt, args); + va_end(args); + fputs("\n", mStream); + mNeedsIndent = true; + } + + void println() { + doIndent(); + fputs("\n", mStream); + mNeedsIndent = true; + } + +private: + void doIndent() { + if (mNeedsIndent) { + int numSpaces = mIndent * mIndentSize; + while (numSpaces > 0) { + fputs(" ", mStream); + numSpaces--; + } + mNeedsIndent = false; + } + } + + FILE* mStream; + const int mIndentSize; + int mIndent; + bool mNeedsIndent; +}; + +#endif // __INDENT_PRINTER_H + |