Add firstLineChar member in ASBeautifier + Use symmetrical layout for closing brace in template argument list:

template
<
    class Argument
>
This commit is contained in:
Peter Vingelmann 2016-09-10 04:29:09 +02:00
parent a28cde5425
commit 25c4fdac73
2 changed files with 20 additions and 3 deletions

View File

@ -252,6 +252,7 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other)
currentNonSpaceCh = other.currentNonSpaceCh; currentNonSpaceCh = other.currentNonSpaceCh;
currentNonLegalCh = other.currentNonLegalCh; currentNonLegalCh = other.currentNonLegalCh;
prevNonLegalCh = other.prevNonLegalCh; prevNonLegalCh = other.prevNonLegalCh;
lineFirstChar = other.lineFirstChar;
} }
/** /**
@ -365,6 +366,7 @@ void ASBeautifier::init(ASSourceIterator* iter)
prevNonLegalCh = '{'; prevNonLegalCh = '{';
currentNonLegalCh = '{'; currentNonLegalCh = '{';
quoteChar = ' '; quoteChar = ' ';
lineFirstChar = ' ';
probationHeader = NULL; probationHeader = NULL;
lastLineHeader = NULL; lastLineHeader = NULL;
backslashEndsPrevLine = false; backslashEndsPrevLine = false;
@ -879,6 +881,7 @@ string ASBeautifier::beautify(const string& originalLine)
haveLineContinuationChar = false; haveLineContinuationChar = false;
lineOpeningBlocksNum = 0; lineOpeningBlocksNum = 0;
lineClosingBlocksNum = 0; lineClosingBlocksNum = 0;
lineFirstChar = ' ';
if (isImmediatelyPostObjCMethodDefinition) if (isImmediatelyPostObjCMethodDefinition)
clearObjCMethodDefinitionAlignment(); clearObjCMethodDefinitionAlignment();
@ -920,6 +923,7 @@ string ASBeautifier::beautify(const string& originalLine)
line = trim(originalLine); line = trim(originalLine);
if (line.length() > 0) if (line.length() > 0)
{ {
lineFirstChar = line[0];
if (line[0] == '{') if (line[0] == '{')
lineBeginsWithOpenBracket = true; lineBeginsWithOpenBracket = true;
else if (line[0] == '}') else if (line[0] == '}')
@ -2110,6 +2114,21 @@ void ASBeautifier::computePreliminaryIndentation()
} }
} }
if (isInTemplate)
{
// Use symmetrical layout for closing brace in template argument list:
//
// template
// <
// class Argument
// >
if (lineFirstChar == '>' && !lineStartsInComment)
{
if (!inStatementIndentStack->empty())
spaceIndentCount -= inStatementIndentStack->back();
}
}
if (isInClassInitializer || isInEnumTypeID) if (isInClassInitializer || isInEnumTypeID)
{ {
indentCount += classInitializerIndents; indentCount += classInitializerIndents;

View File

@ -279,7 +279,6 @@ protected: // functions definitions are at the end of ASResource.cpp
bool isCharPotentialOperator(char ch) const; bool isCharPotentialOperator(char ch) const;
bool isDigitSeparator(const string& line, int i) const; bool isDigitSeparator(const string& line, int i) const;
char peekNextChar(const string& line, int i) const; char peekNextChar(const string& line, int i) const;
}; // Class ASBase }; // Class ASBase
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -517,6 +516,7 @@ private: // variables
char currentNonSpaceCh; char currentNonSpaceCh;
char currentNonLegalCh; char currentNonLegalCh;
char prevNonLegalCh; char prevNonLegalCh;
char lineFirstChar;
}; // Class ASBeautifier }; // Class ASBeautifier
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -591,7 +591,6 @@ private:
// SQL variables // SQL variables
bool nextLineIsDeclareIndent; // begin declare section indent is reached bool nextLineIsDeclareIndent; // begin declare section indent is reached
bool isInDeclareSection; // need to indent a declare section bool isInDeclareSection; // need to indent a declare section
}; // Class ASEnhancer }; // Class ASEnhancer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -987,7 +986,6 @@ private: // inline functions
// sort comparison functions for ASResource // sort comparison functions for ASResource
bool sortOnLength(const string* a, const string* b); bool sortOnLength(const string* a, const string* b);
bool sortOnName(const string* a, const string* b); bool sortOnName(const string* a, const string* b);
} // end of astyle namespace } // end of astyle namespace
// end of astyle namespace -------------------------------------------------- // end of astyle namespace --------------------------------------------------