From f9effd16b3f19ec42053db2976e9ac04614b9b60 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Thu, 8 Sep 2011 14:47:19 +0200
Subject: [PATCH] C++ function signature: Fix problem with multiline
 declarations.

QTextCursor::selectedText() has null chars where the tokenizer expects
newlines.

Change-Id: I15ae87ef8525c89812a61b80abda91d36bf56576
Reviewed-on: http://codereview.qt-project.org/4450
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
---
 src/plugins/cppeditor/cppfunctiondecldeflink.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 5d2b2f1b605..5b80d062a0e 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -437,10 +437,17 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
     // parse the current source declaration
     TypeOfExpression typeOfExpression; // ### just need to preprocess...
     typeOfExpression.init(sourceDocument, snapshot);
-    const QString newDecl = typeOfExpression.preprocess(
-                linkSelection.selectedText()) + QLatin1String("{}");
+
+    QString newDeclText = linkSelection.selectedText();
+    for (int i = 0; i < newDeclText.size(); ++i) {
+        if (newDeclText.at(i).toAscii() == 0)
+            newDeclText[i] = QLatin1Char('\n');
+    }
+    newDeclText.append(QLatin1String("{}"));
+    const QString newDeclTextPreprocessed = typeOfExpression.preprocess(newDeclText);
+
     Document::Ptr newDeclDoc = Document::create(QLatin1String("<decl>"));
-    newDeclDoc->setSource(newDecl.toUtf8());
+    newDeclDoc->setSource(newDeclTextPreprocessed.toUtf8());
     newDeclDoc->parse(Document::ParseDeclaration);
     newDeclDoc->check();
 
-- 
GitLab