summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-22 23:10:29 +0000
committerChris Lattner <sabre@nondot.org>2009-08-22 23:10:29 +0000
commitc5a227ddd1fa09cd66e4fd1c0473be5c2b4f8f32 (patch)
tree91d4c4c97128df538b6bf7b9c675708a62a4e086 /lib
parentf682f3d019794d4402b73701a06a4bb117f5d5e7 (diff)
downloadllvm-c5a227ddd1fa09cd66e4fd1c0473be5c2b4f8f32.tar.gz
llvm-c5a227ddd1fa09cd66e4fd1c0473be5c2b4f8f32.tar.bz2
llvm-c5a227ddd1fa09cd66e4fd1c0473be5c2b4f8f32.tar.xz
add a raw_ostream::indent method, to be used like:
OS.indent(i) << "whatever"; people seem to like indenting things ;-) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/raw_ostream.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 917e6be669..94507bd67b 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -289,6 +289,23 @@ raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
}
}
+/// indent - Insert 'NumSpaces' spaces.
+raw_ostream &raw_ostream::indent(unsigned NumSpaces) {
+ const char *Spaces = " ";
+
+ // Usually the indentation is small, handle it with a fastpath.
+ if (NumSpaces <= 16)
+ return write(Spaces, NumSpaces);
+
+ while (NumSpaces) {
+ unsigned NumToWrite = std::min(NumSpaces, 16U);
+ write(Spaces, NumToWrite);
+ NumSpaces -= NumToWrite;
+ }
+ return *this;
+}
+
+
//===----------------------------------------------------------------------===//
// Formatted Output
//===----------------------------------------------------------------------===//