23 size_t getLineWidth(
const string& str,
size_t pos) {
24 size_t startPos = pos;
25 while (pos < str.size() && str[pos] !=
'\n')
27 return pos - startPos;
30 void printSpaces(ostream& out,
size_t howMany) {
41 while (columnCount > 0) {
52 const string& prefix,
const string& suffix) {
53 auto_ptr<Col> col(
new Col());
56 col->flushLeft = flushLeft;
67 return _cols[col]->text;
74 const string& text =
_cols[col]->text.str();
78 while (pos < text.size()) {
79 size_t width = getLineWidth(text, pos);
86 if (text[pos] ==
'\n')
89 widths[col] = maxWidth;
97 if (poses[col] <
_cols[col]->text.str().size()) {
107 out <<
_cols[col]->prefix;
109 const string& text =
_cols[col]->text.str();
110 size_t& pos = poses[col];
111 size_t width = getLineWidth(text, pos);
113 if (!
_cols[col]->flushLeft)
114 printSpaces(out, widths[col] - width);
116 while (pos < text.size()) {
117 if (text[pos] ==
'\n') {
125 if (
_cols[col]->flushLeft)
126 printSpaces(out, widths[col] - width);
128 out <<
_cols[col]->suffix;
137 out << tmp.
str().c_str();
148 fputs(str.str().c_str(), out);
void print(FILE *out, const ColumnPrinter &pr)
ostream & operator<<(ostream &out, const ColumnPrinter &printer)
void exceptionSafePushBack(Container &container, auto_ptr< Element > pointer)
ostream & operator[](size_t col)
void print(ostream &out) const
size_t getColumnCount() const
ColumnPrinter(size_t columnCount=0)
void addColumn(bool flushLeft=true, const string &prefix=" ", const string &suffix="")
void setPrefix(const string &prefix)
A replacement for stringstream.