Commit cd190875 authored by hirschen's avatar hirschen Committed by Thorbjørn Lindeijer
Browse files

fix indentation of template functions



template functions where treated as unfinished lines by the indenter and so
the result of:

template<typename T>
void myFunc()
{

}

was indented as:

template<typename T>
	void myFunc()
{

}

which is pretty ugly and non-standard.

Merge-request: 1615
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent f62ecb37
......@@ -49,7 +49,8 @@ Constants::Constants() :
m_iflikeKeyword(QLatin1String("\\b(?:catch|do|for|if|while|foreach)\\b")),
m_caseLabel(QLatin1String("^\\s*(?:case\\b(?:[^:]|::)+"
"|(?:public|protected|private|signals|Q_SIGNALS|default)(?:\\s+slots|\\s+Q_SLOTS)?\\s*"
"):"))
"):")),
m_templateFunc(QLatin1String("template<.*>"))
{
m_literal.setMinimal(true);
m_inlineCComment.setMinimal(true);
......@@ -59,4 +60,5 @@ Constants::Constants() :
Q_ASSERT(m_braceX.isValid());
Q_ASSERT(m_iflikeKeyword.isValid());
Q_ASSERT(m_caseLabel.isValid());
Q_ASSERT(m_templateFunc.isValid());
}
......@@ -54,6 +54,7 @@ struct Constants {
QRegExp m_braceX;
QRegExp m_iflikeKeyword;
QRegExp m_caseLabel;
QRegExp m_templateFunc;
};
/* The "linizer" is a group of functions and variables to iterate
......
......@@ -647,10 +647,11 @@ bool Indenter<Iterator>::isUnfinishedLine()
if ( ! m_constants.m_bracesSemicolon.contains(lastCh) && !yyLine->endsWith(m_constants.m_3dots) ) {
/*
It doesn't end with ';' or similar. If it's neither
"Q_OBJECT" nor "if ( x )", it must be an unfinished line.
"Q_OBJECT" nor "if ( x )" nor is a template function, it must be an unfinished line.
*/
unf = ( yyLine->contains(m_constants.m_qobject) == 0 &&
!matchBracelessControlStatement() );
unf = ( !yyLine->contains(m_constants.m_qobject) &&
!matchBracelessControlStatement() &&
!yyLine->contains(m_constants.m_templateFunc) );
} else if ( lastCh == semicolon ) {
if ( lastParen(*yyLine) == openingParenthesis ) {
/*
......
......@@ -143,7 +143,7 @@ int format(const QString &fileName)
if (p.last().endsWith(colon))
typedIn = colon;
const int indent = Indenter::instance().indentForBottomLine(p.constBegin(), p.constEnd(), typedIn);
const int indent = Indenter::instance().indentForBottomLine(it, p.constBegin(), p.constEnd(), typedIn);
const QString trimmed = line.trimmed();
// Indent the line in the list so that the formatter code sees the indented line.
......
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