From d858a43f0785d1676760d4b5515acfd29c3abaf5 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 20 Jan 2016 10:40:48 +0000 Subject: [PATCH] [grid_layout] avoid extra newline at end of grid --- base/grid_layout.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/base/grid_layout.cc b/base/grid_layout.cc index 5ba12b4..813be44 100644 --- a/base/grid_layout.cc +++ b/base/grid_layout.cc @@ -20,12 +20,21 @@ grid_layout::render(ostream &out) const calc_field_widths(widths); grid::const_iterator row; + bool newline_needed = false; + for (row = grid_.begin(); row != grid_.end(); ++row) { row::const_iterator col; unsigned i; - for (col = row->begin(), i = 0; col != row->end(); ++col, ++i) + + if (newline_needed) { + out << "\n"; + newline_needed = false; + } + + for (col = row->begin(), i = 0; col != row->end(); ++col, ++i) { out << justify(widths[i], *col) << " "; - out << "\n"; + newline_needed = true; + } } }