aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2023-12-08 11:49:01 +0100
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2023-12-08 17:48:39 +0000
commitee75c7276b9ba9fc01f0182d45547038567b6e93 (patch)
tree3eb504543d7b3c54f3f3c57ecffc829d9f9b6638
parent2f49c0830efafe5f9f87a313ed0faa076a3c755e (diff)
ClangFormat: Fix utf8 symbol indentationv12.0.1
Fixes: QTCREATORBUG-29927 Change-Id: I5a5a326e13cbe3a874a66e275ded0c6dea9964d7 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/clangformat/clangformatbaseindenter.cpp6
-rw-r--r--src/plugins/clangformat/tests/clangformat-test.cpp16
-rw-r--r--src/plugins/clangformat/tests/clangformat-test.h1
3 files changed, 21 insertions, 2 deletions
diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp
index 6903491fb0..605ed2801c 100644
--- a/src/plugins/clangformat/clangformatbaseindenter.cpp
+++ b/src/plugins/clangformat/clangformatbaseindenter.cpp
@@ -316,8 +316,10 @@ int forceIndentWithExtraText(QByteArray &buffer,
// A comment at the end of the line appears to prevent clang-format from removing line breaks.
if (dummyText == "/*//*/" || dummyText.isEmpty()) {
if (block.previous().isValid()) {
- const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer,
- block.blockNumber()) + block.previous().text().length();
+ const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(),
+ buffer,
+ block.blockNumber())
+ + block.previous().text().toUtf8().length();
buffer.insert(prevEndOffset, " //");
extraLength += 3;
}
diff --git a/src/plugins/clangformat/tests/clangformat-test.cpp b/src/plugins/clangformat/tests/clangformat-test.cpp
index 80d2cc4da9..a4a85cf906 100644
--- a/src/plugins/clangformat/tests/clangformat-test.cpp
+++ b/src/plugins/clangformat/tests/clangformat-test.cpp
@@ -730,4 +730,20 @@ void ClangFormatTest::testIndentCommentOnNewLine()
}));
}
+void ClangFormatTest::testUtf8SymbolLine()
+{
+ insertLines({"int main()",
+ "{",
+ " cout << \"ä\" << endl;",
+ " return 0;",
+ "}"});
+ m_indenter->indent(*m_cursor, QChar::Null, TextEditor::TabSettings());
+ QCOMPARE(documentLines(),
+ (std::vector<QString>{"int main()",
+ "{",
+ " cout << \"ä\" << endl;",
+ " return 0;",
+ "}"}));
+}
+
} // namespace ClangFormat::Internal
diff --git a/src/plugins/clangformat/tests/clangformat-test.h b/src/plugins/clangformat/tests/clangformat-test.h
index 494ebc85da..d1dba9a13f 100644
--- a/src/plugins/clangformat/tests/clangformat-test.h
+++ b/src/plugins/clangformat/tests/clangformat-test.h
@@ -91,6 +91,7 @@ private slots:
void testIndentInitializeVector();
void testIndentFunctionArgumentOnNewLine();
void testIndentCommentOnNewLine();
+ void testUtf8SymbolLine();
private:
void insertLines(const std::vector<QString> &lines);