- enhancement: Auto insert spaces between #include and <> when reformat

- enhancement: Auto insert spaces between #include and "" when reformat
This commit is contained in:
Roy Qu 2023-07-07 22:33:48 +08:00
parent 5e71973152
commit 55353859d0
4 changed files with 30 additions and 6 deletions

View File

@ -33,6 +33,8 @@ Red Panda C++ Version 2.23
- enhancement: Folder mode in "File in files" dialog.
- enhancement: When open a file, test if it contains binary contains.
- enhancement: Correctly reformat C++ three-way comparision operator "<=>"
- enhancement: Auto insert spaces between #include and <> when reformat
Red Panda C++ Version 2.22

View File

@ -210,6 +210,7 @@ void ASFormatter::init(ASSourceIterator* si)
isInPreprocessor = false;
isInPreprocessorDefineDef = false;
isInPreprocessorBeautify = false;
isInPreprocessorInclude = false;
doesLineStartComment = false;
lineEndsInCommentOnly = false;
lineIsCommentOnly = false;
@ -592,6 +593,13 @@ string ASFormatter::nextLine()
if (currentChar == '"'
|| (currentChar == '\'' && !isDigitSeparator(currentLine, charNum)))
{
if (isInPreprocessor && isInPreprocessorInclude &&
currentChar=='\"') {
if (previousChar!=' ' && previousChar!='\t')
appendSpacePad();
isInPreprocessorInclude=false;
}
formatQuoteOpener();
testForTimeToSplitFormattedLine();
continue;
@ -626,10 +634,18 @@ string ASFormatter::nextLine()
if (isInPreprocessor)
{
if (isInPreprocessorInclude &&
(currentChar=='<' || currentChar=='\"')) {
if (previousChar!=' ' && previousChar!='\t')
appendSpacePad();
isInPreprocessorInclude=false;
}
appendCurrentChar();
continue;
}
if (isInTemplate && shouldCloseTemplates)
{
if (previousNonWSChar == '>' && isWhiteSpace(currentChar) && peekNextChar() == '>')
@ -2673,6 +2689,7 @@ bool ASFormatter::getNextLine(bool emptyLineWasDeleted /*false*/)
&& (previousNonWSChar != '\\'
|| isEmptyLine(currentLine)))
{
isInPreprocessorInclude = false;
isInPreprocessor = false;
isInPreprocessorDefineDef = false;
}
@ -5652,6 +5669,10 @@ void ASFormatter::processPreprocessor()
for (int i = 0; i < addedPreproc; i++)
braceTypeStack->pop_back();
}
}
else if (currentLine.compare(preproc, 7, "include") == 0)
{
isInPreprocessorInclude = true;
}
else if (currentLine.compare(preproc, 6, "define") == 0)
isInPreprocessorDefineDef = true;

View File

@ -940,6 +940,7 @@ private: // variables
bool isInPreprocessor;
bool isInPreprocessorDefineDef;
bool isInPreprocessorBeautify;
bool isInPreprocessorInclude;
bool isInTemplate;
bool doesLineStartComment;
bool lineEndsInCommentOnly;