add a raw_ostream::indent method, to be used like:
authorChris Lattner <sabre@nondot.org>
Sat, 22 Aug 2009 23:10:29 +0000 (23:10 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 22 Aug 2009 23:10:29 +0000 (23:10 +0000)
  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

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index a9d1b5a7a25b979b0ce4f633721bd1cb40a2ff53..c9a8787429f9aaeec84c0d851d7b763626d2b450 100644 (file)
@@ -230,6 +230,10 @@ public:
   // Formatted output, see the format() function in Support/Format.h.
   raw_ostream &operator<<(const format_object_base &Fmt);
 
+  /// indent - Insert 'NumSpaces' spaces.
+  raw_ostream &indent(unsigned NumSpaces);
+  
+  
   /// Changes the foreground color of text that will be output from this point
   /// forward.
   /// @param colors ANSI color to use, the special SAVEDCOLOR can be used to
index 917e6be6699d893bd760a726d4d396b8e62387e0..94507bd67ba004b65ffb2fee6377dc3980962432 100644 (file)
@@ -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
 //===----------------------------------------------------------------------===//