forked from qt-creator/qt-creator
ClangFormat: Fix removal of common prefix and suffix
Amends 61fc1fd452
.
Fixes: QTCREATORBUG-31004
Change-Id: I9fea637d36a97b472204a7601efcec9e0f610eb7
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -433,8 +433,10 @@ static ChangeSet convertReplacements(const QTextDocument *doc,
|
||||
QString replacementText = QString::fromStdString(replacement.getReplacementText().str());
|
||||
replacementText.replace("\r", "");
|
||||
auto sameCharAt = [&](int replacementOffset) {
|
||||
if (replacementText.size() <= replacementOffset || replacementOffset < 0)
|
||||
if (utf16Length == 0 || replacementText.size() <= replacementOffset
|
||||
|| replacementOffset < 0) {
|
||||
return false;
|
||||
}
|
||||
const QChar docChar = doc->characterAt(utf16Offset + replacementOffset);
|
||||
const QChar replacementChar = replacementText.at(replacementOffset);
|
||||
return docChar == replacementChar
|
||||
@@ -444,7 +446,7 @@ static ChangeSet convertReplacements(const QTextDocument *doc,
|
||||
while (sameCharAt(0)) {
|
||||
++utf16Offset;
|
||||
--utf16Length;
|
||||
replacementText = replacementText.mid(1);
|
||||
replacementText.removeFirst();
|
||||
}
|
||||
// remove identical suffix from replacement text
|
||||
while (sameCharAt(utf16Length - 1)) {
|
||||
|
@@ -118,6 +118,7 @@ private slots:
|
||||
void testIndentationInTheBegginingOfLine();
|
||||
void testIndentationReturnAfterIf();
|
||||
void testIndentationReturnAfterIfSomthingFunction();
|
||||
void testReformatQualifier();
|
||||
|
||||
private:
|
||||
void insertLines(const std::vector<QString> &lines);
|
||||
@@ -999,6 +1000,25 @@ void ClangFormatTest::testIndentationReturnAfterIfSomthingFunction()
|
||||
"}"}));
|
||||
}
|
||||
|
||||
void ClangFormatTest::testReformatQualifier()
|
||||
{
|
||||
insertLines({
|
||||
"struct S",
|
||||
"{",
|
||||
" S &operator=(S const &s);",
|
||||
"};",
|
||||
"S &S::operator=(const S &s) {}"
|
||||
});
|
||||
m_extendedIndenter->autoIndent(*m_cursor, TextEditor::TabSettings());
|
||||
const std::vector<QString> expected{
|
||||
"struct S",
|
||||
"{",
|
||||
" S &operator=(S const &s);",
|
||||
"};",
|
||||
"S &S::operator=(S const &s) {}"};
|
||||
QCOMPARE(documentLines(), expected);
|
||||
}
|
||||
|
||||
QObject *createClangFormatTest()
|
||||
{
|
||||
return new ClangFormatTest;
|
||||
|
@@ -96,6 +96,7 @@ PenaltyBreakString: 600
|
||||
PenaltyExcessCharacter: 50
|
||||
PenaltyReturnTypeOnItsOwnLine: 300
|
||||
PointerAlignment: Right
|
||||
QualifierAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
|
Reference in New Issue
Block a user