Do not perform right alignment for assignment and return if line ends with (
This commit is contained in:
parent
063a8b06b6
commit
81b77fc202
@ -1261,15 +1261,17 @@ void ASBeautifier::registerInStatementIndent(const string& line, int i, int spac
|
||||
// text is comment-only
|
||||
int nextProgramChar = getNextProgramCharDistance(line, i);
|
||||
|
||||
// if indent is around the last char in the line, indent instead one indent from the previous indent
|
||||
if (nextProgramChar == remainingCharNum)
|
||||
bool isLastProgramChar = (nextProgramChar == remainingCharNum);
|
||||
|
||||
// if indent is around the last char in the line or the line ends with '(',
|
||||
// then add only one indent from the previous indent
|
||||
if (isLastProgramChar || getLastProgramChar(line, i) == '(')
|
||||
{
|
||||
int previousIndent = spaceTabCount_;
|
||||
if (!inStatementIndentStack->empty())
|
||||
previousIndent = inStatementIndentStack->back();
|
||||
int currIndent = /*2*/ indentLength + previousIndent;
|
||||
if (currIndent > maxInStatementIndent
|
||||
&& line[i] != '{')
|
||||
if (currIndent > maxInStatementIndent && line[i] != '{')
|
||||
currIndent = indentLength * 2 + spaceTabCount_;
|
||||
inStatementIndentStack->push_back(currIndent);
|
||||
if (updateParenStack)
|
||||
@ -1358,6 +1360,55 @@ pair<int, int> ASBeautifier::computePreprocessorIndent()
|
||||
return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last non-whitespace, non-comment character in the line.
|
||||
* if no such character exists, return ' '
|
||||
*
|
||||
* @param i the search starts from this index (must be a program char).
|
||||
*/
|
||||
char ASBeautifier::getLastProgramChar(const string& line, int i) const
|
||||
{
|
||||
bool inComment = false;
|
||||
int remainingCharNum = line.length() - i;
|
||||
char lastProgramChar = ' ';
|
||||
int charDistance;
|
||||
char ch;
|
||||
|
||||
for (charDistance = 0; charDistance < remainingCharNum; charDistance++)
|
||||
{
|
||||
ch = line[i + charDistance];
|
||||
if (inComment)
|
||||
{
|
||||
if (line.compare(i + charDistance, 2, "*/") == 0)
|
||||
{
|
||||
charDistance++;
|
||||
inComment = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (ch == '/')
|
||||
{
|
||||
if (line.compare(i + charDistance, 2, "//") == 0)
|
||||
return lastProgramChar;
|
||||
if (line.compare(i + charDistance, 2, "/*") == 0)
|
||||
{
|
||||
charDistance++;
|
||||
inComment = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastProgramChar = ch;
|
||||
}
|
||||
}
|
||||
else if (!isWhiteSpace(ch))
|
||||
{
|
||||
lastProgramChar = ch;
|
||||
}
|
||||
}
|
||||
|
||||
return lastProgramChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* get distance to the next non-white space, non-comment character in the line.
|
||||
* if no such character exists, return the length remaining to the end of the line.
|
||||
@ -3399,6 +3450,9 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
||||
i += foundIndentableHeader->length() - 1;
|
||||
if (!isInOperator && !isInTemplate)
|
||||
{
|
||||
// Do not align on the right side of the return statement
|
||||
// if this is a continuation line that ends with '('
|
||||
if (getLastProgramChar(line, i) != '(')
|
||||
registerInStatementIndent(line, i, spaceIndentCount, tabIncrementIn, 0, false);
|
||||
isInStatement = true;
|
||||
}
|
||||
@ -3598,6 +3652,9 @@ void ASBeautifier::parseCurrentLine(const string& line)
|
||||
{
|
||||
if (i == 0 && spaceIndentCount == 0)
|
||||
spaceIndentCount += indentLength;
|
||||
// Do not align on the right side of the '=' sign
|
||||
// if this is a continuation line that ends with '('
|
||||
if (getLastProgramChar(line, i) != '(')
|
||||
registerInStatementIndent(line, i, spaceIndentCount, tabIncrementIn, 0, false);
|
||||
isInStatement = true;
|
||||
}
|
||||
|
@ -339,6 +339,7 @@ protected:
|
||||
const vector<const string*>* possibleHeaders) const;
|
||||
const string* findOperator(const string& line, int i,
|
||||
const vector<const string*>* possibleOperators) const;
|
||||
char getLastProgramChar(const string& line, int i) const;
|
||||
int getNextProgramCharDistance(const string& line, int i) const;
|
||||
int indexOf(vector<const string*>& container, const string* element) const;
|
||||
void setBlockIndent(bool state);
|
||||
|
Loading…
x
Reference in New Issue
Block a user