Commit e913f828 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Made a start on correcting indentation

parent 1575e683
...@@ -30,10 +30,14 @@ ...@@ -30,10 +30,14 @@
#include "PrettyPrinter.h" #include "PrettyPrinter.h"
#include "AST.h" #include "AST.h"
#include "Token.h" #include "Token.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <sstream>
#include <cassert> #include <cassert>
#include <QString>
CPLUSPLUS_USE_NAMESPACE CPLUSPLUS_USE_NAMESPACE
PrettyPrinter::PrettyPrinter(Control *control, std::ostream &out) PrettyPrinter::PrettyPrinter(Control *control, std::ostream &out)
...@@ -73,13 +77,38 @@ void PrettyPrinter::outToken(unsigned token) ...@@ -73,13 +77,38 @@ void PrettyPrinter::outToken(unsigned token)
const unsigned end = t.begin(); const unsigned end = t.begin();
_lastToken = token; _lastToken = token;
std::ostringstream oss;
// Preserve non-AST text // Preserve non-AST text
QByteArray ba(_contents.constData() + start, end - start); QByteArray ba(_contents.constData() + start, end - start);
_out << ba.constData(); oss << ba.constData();
// Print the token itself // Print the token itself
QByteArray tt(_contents.constData() + t.begin(), t.length); 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) bool PrettyPrinter::visit(AccessDeclarationAST *ast)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment