📄 asbeautifier.cpp
字号:
isInCase = true;
if (!caseIndent)
--tabCount;
}
else if(newHeader == &AS_DEFAULT)
{
isInCase = true;
if (!caseIndent)
--tabCount;
}
else if (newHeader == &AS_PUBLIC || newHeader == &AS_PROTECTED || newHeader == &AS_PRIVATE)
{
if (( sourceStyle != STYLE_JAVA ) && !isInClassHeader)
--tabCount;
isIndentableHeader = false;
}
//else if ((newHeader == &STATIC || newHeader == &SYNCHRONIZED) &&
// !headerStack->empty() &&
// (headerStack->back() == &STATIC || headerStack->back() == &SYNCHRONIZED))
//{
// isIndentableHeader = false;
//}
else if (newHeader == &AS_STATIC
|| newHeader == &AS_SYNCHRONIZED
|| (newHeader == &AS_CONST && ( sourceStyle != STYLE_JAVA )))
{
if (!headerStack->empty() &&
(headerStack->back() == &AS_STATIC
|| headerStack->back() == &AS_SYNCHRONIZED
|| headerStack->back() == &AS_CONST))
{
isIndentableHeader = false;
}
else
{
isIndentableHeader = false;
probationHeader = newHeader;
}
}
else if (newHeader == &AS_CONST)
{
// this will be entered only if NOT in C style
// since otherwise the CONST would be found to be a probstion header...
//if (sourceStyle != STYLE_JAVA)
// isInConst = true;
isIndentableHeader = false;
}
else if ( (sourceStyle != STYLE_CSHARP) &&
(newHeader == &AS_FOREACH || newHeader == &AS_LOCK
|| newHeader == &AS_UNSAFE || newHeader == &AS_FIXED
|| newHeader == &AS_GET || newHeader == &AS_SET
|| newHeader == &AS_ADD || newHeader == &AS_REMOVE ) )
{
// this will be entered only if in C# style
isIndentableHeader = false;
}
/*
else if (newHeader == &OPERATOR)
{
if (( sourceStyle != STYLE_JAVA ))
isInOperator = true;
isIndentableHeader = false;
}
*/
else if (newHeader == &AS_TEMPLATE)
{
if (( sourceStyle != STYLE_JAVA ))
isInTemplate = true;
isIndentableHeader = false;
}
if (isIndentableHeader)
{
// 3.2.99
//spaceTabCount-=indentLength;
headerStack->push_back(newHeader);
isInStatement = false;
if (indexOf(nonParenHeaders, newHeader) == -1)
{
isInConditional = true;
}
lastLineHeader = newHeader;
}
else
isInHeader = false;
//lastLineHeader = newHeader;
outBuffer.append(newHeader->substr(1));
i += newHeader->length() - 1;
continue;
}
}
if (( sourceStyle != STYLE_JAVA ) && !isalpha(prevCh)
&& CONTAINS_AT(line, AS_OPERATOR, 8, i)
&& !isalnum(line[i+8]))
{
isInOperator = true;
outBuffer.append(AS_OPERATOR.substr(1));
i += 7;
continue;
}
if (ch == '?')
isInQuestion = true;
// special handling of 'case' statements
if (ch == ':')
{
if (line.size() > i+1 && line[i+1] == ':') // look for ::
{
++i;
outBuffer.append(1, ':');
ch = ' ';
continue;
}
else if (( sourceStyle != STYLE_JAVA ) && isInClass && prevNonSpaceCh != ')')
{
--tabCount;
// found a 'private:' or 'public:' inside a class definition
// so do nothing special
}
else if (( sourceStyle != STYLE_JAVA ) && isInClassHeader)
{
// found a 'class A : public B' definition
// so do nothing special
}
else if (isInQuestion)
{
isInQuestion = false;
}
else if (( sourceStyle != STYLE_JAVA ) && prevNonSpaceCh == ')')
{
isInClassHeader = true;
if (i==0)
tabCount += 2;
}
else
{
currentNonSpaceCh = ';'; // so that brackets after the ':' will appear as block-openers
if (isInCase)
{
isInCase = false;
ch = ';'; // from here on, treat char as ';'
}
else // is in a label (e.g. 'label1:')
{
if (labelIndent)
--tabCount; // unindent label by one indent
else
tabCount = 0; // completely flush indent to left
}
}
}
if ((ch == ';' || (parenDepth>0 && ch == ',')) && !inStatementIndentStackSizeStack->empty())
while (inStatementIndentStackSizeStack->back() + (parenDepth>0 ? 1 : 0) < inStatementIndentStack->size())
inStatementIndentStack->pop_back();
// handle ends of statements
if ( (ch == ';' && parenDepth == 0) || ch == '}'/* || (ch == ',' && parenDepth == 0)*/)
{
if (ch == '}')
{
// first check if this '}' closes a previous block, or a static array...
if (!bracketBlockStateStack->empty())
{
bool bracketBlockState = bracketBlockStateStack->back();
bracketBlockStateStack->pop_back();
if (!bracketBlockState)
{
if (!inStatementIndentStackSizeStack->empty())
{
// this bracket is a static array
unsigned previousIndentStackSize = inStatementIndentStackSizeStack->back();
inStatementIndentStackSizeStack->pop_back();
while (previousIndentStackSize < inStatementIndentStack->size())
inStatementIndentStack->pop_back();
parenDepth--;
if (i == 0)
shouldIndentBrackettedLine = false;
if (!parenIndentStack->empty())
{
int poppedIndent = parenIndentStack->back();
parenIndentStack->pop_back();
if (i == 0)
spaceTabCount = poppedIndent;
}
}
continue;
}
}
// this bracket is block closer...
++lineClosingBlocksNum;
if(!inStatementIndentStackSizeStack->empty())
inStatementIndentStackSizeStack->pop_back();
if (!blockParenDepthStack->empty())
{
parenDepth = blockParenDepthStack->back();
blockParenDepthStack->pop_back();
isInStatement = blockStatementStack->back();
blockStatementStack->pop_back();
if (isInStatement)
blockTabCount--;
}
closingBracketReached = true;
int headerPlace = indexOf(*headerStack, &AS_OPEN_BRACKET); // <---
if (headerPlace != -1)
{
const string *popped = headerStack->back();
while (popped != &AS_OPEN_BRACKET)
{
headerStack->pop_back();
popped = headerStack->back();
}
headerStack->pop_back();
if (!tempStacks->empty())
{
vector<const string*> *temp = tempStacks->back();
tempStacks->pop_back();
delete temp;
}
}
ch = ' '; // needed due to cases such as '}else{', so that headers ('else' in this case) will be identified...
}
/*
* Create a temporary snapshot of the current block's header-list in the
* uppermost inner stack in tempStacks, and clear the headerStack up to
* the begining of the block.
* Thus, the next future statement will think it comes one indent past
* the block's '{' unless it specifically checks for a companion-header
* (such as a previous 'if' for an 'else' header) within the tempStacks,
* and recreates the temporary snapshot by manipulating the tempStacks.
*/
if (!tempStacks->back()->empty())
while (!tempStacks->back()->empty())
tempStacks->back()->pop_back();
while (!headerStack->empty() && headerStack->back() != &AS_OPEN_BRACKET)
{
tempStacks->back()->push_back(headerStack->back());
headerStack->pop_back();
}
if (parenDepth == 0 && ch == ';')
isInStatement=false;
isInClassHeader = false;
continue;
}
// check for preBlockStatements ONLY if not within parenthesies
// (otherwise 'struct XXX' statements would be wrongly interpreted...)
if (prevCh == ' ' && !isInTemplate && parenDepth == 0)
{
const string *newHeader = findHeader(line, i, preBlockStatements);
if (newHeader != NULL)
{
isInClassHeader = true;
outBuffer.append(newHeader->substr(1));
i += newHeader->length() - 1;
//if (( sourceStyle != STYLE_JAVA ))
headerStack->push_back(newHeader);
}
}
// Handle operators
//
//// // PRECHECK if a '==' or '--' or '++' operator was reached.
//// // If not, then register an indent IF an assignment operator was reached.
//// // The precheck is important, so that statements such as 'i--==2' are not recognized
//// // to have assignment operators (here, '-=') in them . . .
const string *foundAssignmentOp = NULL;
const string *foundNonAssignmentOp = NULL;
immediatelyPreviousAssignmentOp = NULL;
// Check if an operator has been reached.
foundAssignmentOp = findHeader(line, i, assignmentOperators, false);
foundNonAssignmentOp = findHeader(line, i, nonAssignmentOperators, false);
// Since findHeader's boundry checking was not used above, it is possible
// that both an assignment op and a non-assignment op where found,
// e.g. '>>' and '>>='. If this is the case, treat the LONGER one as the
// found operator.
if (foundAssignmentOp != NULL && foundNonAssignmentOp != NULL)
if (foundAssignmentOp->length() < foundNonAssignmentOp->length())
foundAssignmentOp = NULL;
else
foundNonAssignmentOp = NULL;
if (foundNonAssignmentOp != NULL)
{
if (foundNonAssignmentOp->length() > 1)
{
outBuffer.append(foundNonAssignmentOp->substr(1));
i += foundNonAssignmentOp->length() - 1;
}
}
else if (foundAssignmentOp != NULL)
{
if (foundAssignmentOp->length() > 1)
{
outBuffer.append(foundAssignmentOp->substr(1));
i += foundAssignmentOp->length() - 1;
}
if (!isInOperator && !isInTemplate)
{
registerInStatementIndent(line, i, spaceTabCount, 0, false);
immediatelyPreviousAssignmentOp = foundAssignmentOp;
isInStatement = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -