From 25c4fdac73bbb49517c146d966cf67f40f46d829 Mon Sep 17 00:00:00 2001 From: Peter Vingelmann Date: Sat, 10 Sep 2016 04:29:09 +0200 Subject: [PATCH] Add firstLineChar member in ASBeautifier + Use symmetrical layout for closing brace in template argument list: template < class Argument > --- src/ASBeautifier.cpp | 19 +++++++++++++++++++ src/astyle.h | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ASBeautifier.cpp b/src/ASBeautifier.cpp index ee63aa6..98a6e33 100644 --- a/src/ASBeautifier.cpp +++ b/src/ASBeautifier.cpp @@ -252,6 +252,7 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other) currentNonSpaceCh = other.currentNonSpaceCh; currentNonLegalCh = other.currentNonLegalCh; prevNonLegalCh = other.prevNonLegalCh; + lineFirstChar = other.lineFirstChar; } /** @@ -365,6 +366,7 @@ void ASBeautifier::init(ASSourceIterator* iter) prevNonLegalCh = '{'; currentNonLegalCh = '{'; quoteChar = ' '; + lineFirstChar = ' '; probationHeader = NULL; lastLineHeader = NULL; backslashEndsPrevLine = false; @@ -879,6 +881,7 @@ string ASBeautifier::beautify(const string& originalLine) haveLineContinuationChar = false; lineOpeningBlocksNum = 0; lineClosingBlocksNum = 0; + lineFirstChar = ' '; if (isImmediatelyPostObjCMethodDefinition) clearObjCMethodDefinitionAlignment(); @@ -920,6 +923,7 @@ string ASBeautifier::beautify(const string& originalLine) line = trim(originalLine); if (line.length() > 0) { + lineFirstChar = line[0]; if (line[0] == '{') lineBeginsWithOpenBracket = true; 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) { indentCount += classInitializerIndents; diff --git a/src/astyle.h b/src/astyle.h index c910942..0a10072 100644 --- a/src/astyle.h +++ b/src/astyle.h @@ -279,7 +279,6 @@ protected: // functions definitions are at the end of ASResource.cpp bool isCharPotentialOperator(char ch) const; bool isDigitSeparator(const string& line, int i) const; char peekNextChar(const string& line, int i) const; - }; // Class ASBase //----------------------------------------------------------------------------- @@ -517,6 +516,7 @@ private: // variables char currentNonSpaceCh; char currentNonLegalCh; char prevNonLegalCh; + char lineFirstChar; }; // Class ASBeautifier //----------------------------------------------------------------------------- @@ -591,7 +591,6 @@ private: // SQL variables bool nextLineIsDeclareIndent; // begin declare section indent is reached bool isInDeclareSection; // need to indent a declare section - }; // Class ASEnhancer //----------------------------------------------------------------------------- @@ -987,7 +986,6 @@ private: // inline functions // sort comparison functions for ASResource bool sortOnLength(const string* a, const string* b); bool sortOnName(const string* a, const string* b); - } // end of astyle namespace // end of astyle namespace --------------------------------------------------