summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus/PrettyPrinter.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-05-13 09:31:20 +0200
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-05-13 16:07:43 +0200
commite913f8289bc6149906bd8cfccd065ab3312236e3 (patch)
tree47ec3c8b125db080f71bbe39ccd0fc2cf77a47ca /src/shared/cplusplus/PrettyPrinter.cpp
parent1575e6836d73ec32b9fbfd4517f6740e0f8235e5 (diff)
downloadqt-creator-e913f8289bc6149906bd8cfccd065ab3312236e3.tar.gz
Made a start on correcting indentation
Diffstat (limited to 'src/shared/cplusplus/PrettyPrinter.cpp')
-rw-r--r--src/shared/cplusplus/PrettyPrinter.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/shared/cplusplus/PrettyPrinter.cpp b/src/shared/cplusplus/PrettyPrinter.cpp
index c97de44140..da116f7e7d 100644
--- a/src/shared/cplusplus/PrettyPrinter.cpp
+++ b/src/shared/cplusplus/PrettyPrinter.cpp
@@ -30,10 +30,14 @@
#include "PrettyPrinter.h"
#include "AST.h"
#include "Token.h"
+
#include <iostream>
#include <string>
+#include <sstream>
#include <cassert>
+#include <QString>
+
CPLUSPLUS_USE_NAMESPACE
PrettyPrinter::PrettyPrinter(Control *control, std::ostream &out)
@@ -73,13 +77,38 @@ void PrettyPrinter::outToken(unsigned token)
const unsigned end = t.begin();
_lastToken = token;
+ std::ostringstream oss;
+
// Preserve non-AST text
QByteArray ba(_contents.constData() + start, end - start);
- _out << ba.constData();
+ oss << ba.constData();
// Print the token itself
QByteArray tt(_contents.constData() + t.begin(), t.length);
- _out << tt.constData();
+ oss << tt.constData();
+
+ QString stuff = QString::fromUtf8(oss.str().c_str());
+ QString indent = QString(_depth * 4, QLatin1Char(' '));
+
+ int from = 0;
+ int index = 0;
+ while ((index = stuff.indexOf(QLatin1Char('\n'), from)) != -1) {
+ from = index + 1;
+ int firstNonWhitespace = from;
+
+ while (firstNonWhitespace < stuff.length()) {
+ const QChar c = stuff.at(firstNonWhitespace);
+ if (c.isSpace() && c != QLatin1Char('\n'))
+ ++firstNonWhitespace;
+ else
+ break;
+ }
+
+ if (firstNonWhitespace != from)
+ stuff.replace(from, firstNonWhitespace - from, indent);
+ }
+
+ _out << stuff.toUtf8().constData();
}
bool PrettyPrinter::visit(AccessDeclarationAST *ast)