Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
e913f828
Commit
e913f828
authored
May 13, 2009
by
Thorbjørn Lindeijer
Browse files
Made a start on correcting indentation
parent
1575e683
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/shared/cplusplus/PrettyPrinter.cpp
View file @
e913f828
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment