Skip to content
GitLab
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
6f19835f
Commit
6f19835f
authored
Oct 25, 2010
by
Christian Kamm
Browse files
C++ indenter: Ensure indent and padding are non-negative.
Reviewed-by: Roberto Raggi
parent
de187cb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/cpptools/cppcodeformatter.cpp
View file @
6f19835f
...
...
@@ -1247,6 +1247,12 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*
indentDepth
=
m_indentSize
;
break
;
}
// ensure padding and indent are >= 0
*
indentDepth
=
qMax
(
0
,
*
indentDepth
);
*
savedIndentDepth
=
qMax
(
0
,
*
savedIndentDepth
);
*
paddingDepth
=
qMax
(
0
,
*
paddingDepth
);
*
savedPaddingDepth
=
qMax
(
0
,
*
savedPaddingDepth
);
}
void
QtStyleCodeFormatter
::
adjustIndent
(
const
QList
<
CPlusPlus
::
Token
>
&
tokens
,
int
lexerState
,
int
*
indentDepth
,
int
*
paddingDepth
)
const
...
...
@@ -1287,7 +1293,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
if
(
topState
.
type
==
expression
&&
previousState
.
type
==
declaration_start
)
{
*
paddingDepth
=
m_indentSize
;
}
else
if
(
topState
.
type
==
ternary_op
)
{
*
paddingDepth
-=
2
;
if
(
*
paddingDepth
>=
2
)
*
paddingDepth
-=
2
;
else
*
paddingDepth
=
0
;
}
break
;
case
T_LBRACE
:
{
...
...
@@ -1382,8 +1391,12 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
break
;
case
T_LESS_LESS
:
case
T_GREATER_GREATER
:
if
(
topState
.
type
==
stream_op
||
topState
.
type
==
stream_op_cont
)
*
paddingDepth
-=
3
;
// to align << with <<
if
(
topState
.
type
==
stream_op
||
topState
.
type
==
stream_op_cont
)
{
if
(
*
paddingDepth
>=
3
)
*
paddingDepth
-=
3
;
// to align << with <<
else
*
paddingDepth
=
0
;
}
break
;
case
T_COMMENT
:
case
T_DOXY_COMMENT
:
...
...
@@ -1395,7 +1408,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
&&
(
kind
==
T_COMMENT
||
kind
==
T_DOXY_COMMENT
)
&&
(
lexerState
==
Lexer
::
State_Default
||
tokens
.
size
()
!=
1
))
{
*
indentDepth
-=
m_indentSize
;
if
(
*
indentDepth
>=
m_indentSize
)
*
indentDepth
-=
m_indentSize
;
else
*
indentDepth
=
0
;
}
break
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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