From 0631e9642e7c8b615edb9bf31e3fcd95784b1eef Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Wed, 23 Feb 2011 15:45:51 -0300 Subject: Empty lines from custom code must be cropped. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to avoid lines composed only of irritating trailing spaces. Reviewed by Bruno Araújo Reviewed by Luciano Wolf --- generator.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/generator.cpp b/generator.cpp index 376f56050..d1e89fd32 100644 --- a/generator.cpp +++ b/generator.cpp @@ -242,16 +242,22 @@ QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor) } } + static QRegExp emptyLine("\\s*[\\r]?[\\n]?\\s*"); + foreach(QString line, lst) { - while (line.end()->isSpace()) - line.chop(1); - int limit = 0; - for(int i = 0; i < spacesToRemove; ++i) { - if (!line[i].isSpace()) - break; - limit++; + if (!line.isEmpty() && !emptyLine.exactMatch(line)) { + while (line.end()->isSpace()) + line.chop(1); + int limit = 0; + for(int i = 0; i < spacesToRemove; ++i) { + if (!line[i].isSpace()) + break; + limit++; + } + + s << indentor << line.remove(0, limit); } - s << indentor << line.remove(0, limit) << endl; + s << endl; } return s; } -- cgit v1.2.3