1 //===-- llvm/Support/FormattedStream.cpp - Formatted streams ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the implementation of formatted_raw_ostream.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/FormattedStream.h"
18 /// ComputeColumn - Examine the current output and figure out which
19 /// column we end up in after output.
21 void formatted_raw_ostream::ComputeColumn() {
22 // Keep track of the current column by scanning the string for
25 // The buffer may have been allocated underneath us.
26 if (Scanned == 0 && GetNumBytesInBuffer() != 0) {
30 while (Scanned != end()) {
32 if (*Scanned == '\n' || *Scanned == '\r')
34 else if (*Scanned == '\t')
35 // Assumes tab stop = 8 characters.
36 ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;
41 /// PadToColumn - Align the output to some column number.
43 /// \param NewCol - The column to move to.
44 /// \param MinPad - The minimum space to give after the most recent
45 /// I/O, even if the current column + minpad > newcol.
47 void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) {
48 // Figure out what's in the buffer and add it to the column count.
51 // Output spaces until we reach the desired column.
52 unsigned num = NewCol - ColumnScanned;
53 if (NewCol < ColumnScanned || num < MinPad)
56 // Keep a buffer of spaces handy to speed up processing.
57 const char *Spaces = " "
60 assert(num < MAX_COLUMN_PAD && "Unexpectedly large column padding");
65 /// fouts() - This returns a reference to a formatted_raw_ostream for
66 /// standard output. Use it like: fouts() << "foo" << "bar";
67 formatted_raw_ostream &llvm::fouts() {
68 static formatted_raw_ostream S(outs());
72 /// ferrs() - This returns a reference to a formatted_raw_ostream for
73 /// standard error. Use it like: ferrs() << "foo" << "bar";
74 formatted_raw_ostream &llvm::ferrs() {
75 static formatted_raw_ostream S(errs());