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"
19 /// ComputeColumn - Examine the current output and figure out which
20 /// column we end up in after output.
22 void formatted_raw_ostream::ComputeColumn() {
23 // Keep track of the current column by scanning the string for
26 // The buffer may have been allocated underneath us.
27 if (Scanned == 0 && GetNumBytesInBuffer() != 0) {
31 while (Scanned != end()) {
33 if (*Scanned == '\n' || *Scanned == '\r')
35 else if (*Scanned == '\t')
36 // Assumes tab stop = 8 characters.
37 ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;
42 /// PadToColumn - Align the output to some column number.
44 /// \param NewCol - The column to move to.
45 /// \param MinPad - The minimum space to give after the most recent
46 /// I/O, even if the current column + minpad > newcol.
48 void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) {
49 // Figure out what's in the buffer and add it to the column count.
52 // Output spaces until we reach the desired column.
53 unsigned num = NewCol - ColumnScanned;
54 if (NewCol < ColumnScanned || num < MinPad)
57 // Keep a buffer of spaces handy to speed up processing.
58 const char *Spaces = " "
61 assert(num < MAX_COLUMN_PAD && "Unexpectedly large column padding");
66 /// fouts() - This returns a reference to a formatted_raw_ostream for
67 /// standard output. Use it like: fouts() << "foo" << "bar";
68 formatted_raw_ostream &llvm::fouts() {
69 static formatted_raw_ostream S(outs());
73 /// ferrs() - This returns a reference to a formatted_raw_ostream for
74 /// standard error. Use it like: ferrs() << "foo" << "bar";
75 formatted_raw_ostream &llvm::ferrs() {
76 static formatted_raw_ostream S(errs());