diff --git a/NEWS.md b/NEWS.md index 09019e24..97fb4b0a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/tools/astyle/ASFormatter.cpp b/tools/astyle/ASFormatter.cpp index 4739b638..9b82ba0d 100644 --- a/tools/astyle/ASFormatter.cpp +++ b/tools/astyle/ASFormatter.cpp @@ -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,7 +5669,11 @@ 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; } diff --git a/tools/astyle/ASResource.cpp b/tools/astyle/ASResource.cpp index 0888b599..710b7562 100644 --- a/tools/astyle/ASResource.cpp +++ b/tools/astyle/ASResource.cpp @@ -240,8 +240,8 @@ void ASResource::buildCastOperators(vector* castOperators) */ void ASResource::buildHeaders(vector* headers, int fileType, bool beautifier) { - const size_t elements = 25; - headers->reserve(elements); + const size_t elements = 25; + headers->reserve(elements); headers->emplace_back(&AS_IF); headers->emplace_back(&AS_ELSE); @@ -262,7 +262,7 @@ void ASResource::buildHeaders(vector* headers, int fileType, bool { headers->emplace_back(&_AS_TRY); // __try headers->emplace_back(&_AS_FINALLY); // __finally - headers->emplace_back(&_AS_EXCEPT); // __except + headers->emplace_back(&_AS_EXCEPT); // __except } if (fileType == JAVA_TYPE) { @@ -295,7 +295,7 @@ void ASResource::buildHeaders(vector* headers, int fileType, bool } } - assert(headers->size() < elements); + assert(headers->size() < elements); sort(headers->begin(), headers->end(), sortOnName); } diff --git a/tools/astyle/astyle.h b/tools/astyle/astyle.h index 91185fe7..b2fc8855 100644 --- a/tools/astyle/astyle.h +++ b/tools/astyle/astyle.h @@ -939,7 +939,8 @@ private: // variables bool noTrimCommentContinuation; bool isInPreprocessor; bool isInPreprocessorDefineDef; - bool isInPreprocessorBeautify; + bool isInPreprocessorBeautify; + bool isInPreprocessorInclude; bool isInTemplate; bool doesLineStartComment; bool lineEndsInCommentOnly;