📄 astyle.h
字号:
int leadingWhiteSpaces; int maxInStatementIndent; int templateDepth; int prevFinalLineSpaceTabCount; int prevFinalLineTabCount; int defineTabCount; char quoteChar; char prevNonSpaceCh; char currentNonSpaceCh; char currentNonLegalCh; char prevNonLegalCh; protected: // inline functions // check if a specific character can be used in a legal variable/method/class name inline bool isLegalNameChar(char ch) const { return (isalnum(ch) || ch == '.' || ch == '_' || (isJavaStyle && ch == '$') || (isCStyle && ch == '~') || (isSharpStyle && ch == '@')); // may be used as a prefix } // check if a specific character is a whitespace character inline bool isWhiteSpace(char ch) const { return (ch == ' ' || ch == '\t'); }};class ASEnhancer{ public: // functions ASEnhancer(); ~ASEnhancer(); void init(int, string, bool, bool, bool, bool, bool); void enhance(string &line); bool findKeyword(const string &line, int i, const char *header) const; char peekNextChar(const string &line, int i) const; private: // options from command line or options file // X ending prevents conflict with ASBeautifier variables int indentLengthX; bool useTabsX; bool isCStyleX; bool isJavaStyleX; bool isSharpStyleX; bool caseIndentX; bool emptyLineFillX; // parsing variables int lineNumber; bool isInQuote; bool isInComment; char quoteChar; // unindent variables int bracketCount; int switchDepth; bool lookingForCaseBracket; bool unindentNextLine; // struct used by ParseFormattedLine function // contains variables used to unindent the case blocks struct switchVariables { int switchBracketCount; int unindentDepth; bool unindentCase; }; switchVariables sw; // switch variables struct vector<switchVariables> swVector; // stack vector of switch variables // event table variables bool nextLineIsEventTable; // begin event table is reached bool isInEventTable; // need to indent an event table // stringstream for trace stringstream *traceOut; private: // private functions int indentLine(string &line, const int indent) const; int unindentLine(string &line, const int unindent) const; private: // inline functions // check if a specific character can be used in a legal variable/method/class name inline bool isLegalNameCharX(char ch) const { return (isalnum(ch) || ch == '.' || ch == '_' || (isJavaStyleX && ch == '$') || (isCStyleX && ch == '~') || (isSharpStyleX && ch == '@')); // may be used as a prefix } // check if a specific character is a whitespace character inline bool isWhiteSpaceX(char ch) const { return (ch == ' ' || ch == '\t'); }};class ASFormatter : public ASBeautifier, private ASEnhancer{ public: ASFormatter(); virtual ~ASFormatter(); virtual void init(ASSourceIterator* iter); virtual bool hasMoreLines() const; virtual string nextLine(); void setBracketFormatMode(BracketMode mode); void setBreakClosingHeaderBracketsMode(bool state); void setOperatorPaddingMode(bool mode); void setParensOutsidePaddingMode(bool mode); void setParensInsidePaddingMode(bool mode); void setParensUnPaddingMode(bool state); void setBreakOneLineBlocksMode(bool state); void setSingleStatementsMode(bool state); void setTabSpaceConversionMode(bool state); void setBreakBlocksMode(bool state); void setBreakClosingHeaderBlocksMode(bool state); void setBreakElseIfsMode(bool state); string traceFileName; private: void ASformatter(ASFormatter ©); // not to be imlpemented void operator=(ASFormatter&); // not to be implemented void staticInit(); void goForward(int i); void trimNewLine(); char peekNextChar() const; BracketType getBracketType(); bool getNextChar(); bool isBeforeComment() const; bool isBeforeLineEndComment(int startPos) const; bool isNextWordSharpAccessor() const; bool isPointerOrReference() const; bool isUnaryMinus() const; bool isInExponent() const; bool isOneLineBlockReached() const; bool lineBeginsWith(char charToCheck) const; void appendChar(char ch, bool canBreakLine = true); void appendCharInsideComments(); void appendSequence(const string &sequence, bool canBreakLine = true); void appendSpacePad(); void appendSpaceAfter(); void breakLine(); void padOperators(const string *newOperator); void padParens(); void formatBrackets(BracketType bracketType); void formatArrayBrackets(BracketType bracketType, bool isOpeningArrayBracket); void adjustComments(); const string *findHeader(const vector<const string*> &headers, bool checkBoundry = true); static vector<const string*> headers; static vector<const string*> nonParenHeaders; static vector<const string*> preDefinitionHeaders; static vector<const string*> preCommandHeaders; static vector<const string*> operators; static vector<const string*> assignmentOperators; static vector<const string*> castOperators; ASSourceIterator *sourceIterator; vector<const string*> *preBracketHeaderStack; vector<BracketType> *bracketTypeStack; vector<int> *parenStack; string readyFormattedLine; string currentLine; string formattedLine; const string *currentHeader; const string *previousOperator; // used ONLY by pad=oper char currentChar; char previousChar; char previousNonWSChar; char previousCommandChar; char quoteChar; int charNum; int spacePadNum; int templateDepth; int traceLineNumber; size_t formattedLineCommentNum; // comment location on formattedLine size_t previousReadyFormattedLineLength; BracketMode bracketFormatMode; BracketType previousBracketType; bool isVirgin; bool shouldPadOperators; bool shouldPadParensOutside; bool shouldPadParensInside; bool shouldUnPadParens; bool shouldConvertTabs; bool isInLineComment; bool isInComment; bool isInPreprocessor; bool isInTemplate; // true both in template definitions (e.g. template<class A>) and template usage (e.g. F<int>). bool doesLineStartComment; bool isInQuote; bool isInVerbatimQuote; bool haveLineContinuationChar; bool isInQuoteContinuation; bool isInBlParen; bool isSpecialChar; bool isNonParenHeader; bool foundQuestionMark; bool foundPreDefinitionHeader; bool foundNamespaceHeader; bool foundClassHeader; bool foundPreCommandHeader; bool foundCastOperator; bool isInLineBreak; bool endOfCodeReached; bool lineCommentNoIndent; bool isLineReady; bool isPreviousBracketBlockRelated; bool isInPotentialCalculation; bool isCharImmediatelyPostComment; bool isPreviousCharPostComment; bool isCharImmediatelyPostLineComment; bool isCharImmediatelyPostOpenBlock; bool isCharImmediatelyPostCloseBlock; bool isCharImmediatelyPostTemplate; bool shouldBreakOneLineBlocks; bool shouldReparseCurrentChar; bool shouldBreakOneLineStatements;// bool shouldBreakLineAfterComments; bool shouldBreakClosingHeaderBrackets; bool shouldBreakElseIfs; bool passedSemicolon; bool passedColon; bool isImmediatelyPostComment; bool isImmediatelyPostLineComment; bool isImmediatelyPostEmptyBlock; bool isImmediatelyPostPreprocessor; bool shouldBreakBlocks; bool shouldBreakClosingHeaderBlocks; bool isPrependPostBlockEmptyLineRequested; bool isAppendPostBlockEmptyLineRequested; bool prependEmptyLine; bool appendOpeningBracket; bool foundClosingHeader; bool isInHeader; bool isImmediatelyPostHeader; bool isInCase; bool isInSharpGenericDefinition; private: // inline functions // append the CURRENT character (curentChar)to the current formatted line. inline void appendCurrentChar(bool canBreakLine = true) { appendChar(currentChar, canBreakLine); } // check if a specific sequence exists in the current placement of the current line inline bool isSequenceReached(const char *sequence) const { return currentLine.compare(charNum, strlen(sequence), sequence) == 0; }};} // end of namespace astyle#endif // closes ASTYLE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -