C++: Lambda formatting issues.

Fix code formatting in cases when '{' and '}' appear within expression
context (ex. lambda expression, initializer lists).

Change-Id: I42b28170a8d6d5fd08a9a1a8d8e7698219c18966
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
This commit is contained in:
Flex Ferrum
2012-02-19 14:35:41 +04:00
committed by Erik Verbruggen
parent 48b4abe877
commit 4ca6c51c7f
4 changed files with 91 additions and 8 deletions

View File

@@ -120,6 +120,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
QString text = textToProcess;
const QString blockText = tc.block().text().mid(tc.positionInBlock());
const QString trimmedBlockText = blockText.trimmed();
const int length = qMin(blockText.length(), textToProcess.length());
const QChar previousChar = doc->characterAt(tc.selectionEnd() - 1);
@@ -190,10 +191,14 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
QString result;
foreach (const QChar &ch, text) {
if (ch == QLatin1Char('(')) result += ')';
else if (ch == QLatin1Char('[')) result += ']';
else if (ch == QLatin1Char('"')) result += '"';
else if (ch == QLatin1Char('\'')) result += '\'';
if (ch == QLatin1Char('(')) result += QLatin1Char(')');
else if (ch == QLatin1Char('[')) result += QLatin1Char(']');
else if (ch == QLatin1Char('"')) result += QLatin1Char('"');
else if (ch == QLatin1Char('\'')) result += QLatin1Char('\'');
// Handle '{' appearance within functinon call context
else if (ch == QLatin1Char('{') && !trimmedBlockText.isEmpty() && trimmedBlockText.at(0) == QLatin1Char(')'))
result += QLatin1Char('}');
}
return result;