C++: Avoid superfluous * in comment continuation

This fixes the issue pointed below and the general case
int which superfluous asterisks are generated.

Task-number: QTCREATORBUG-6823
Change-Id: I1c8659fb5734609d90cfad052804943b8b99d5df
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Leandro Melo
2012-01-23 23:08:08 +01:00
parent 8e3c88f02b
commit fa34576f3f

View File

@@ -2332,32 +2332,43 @@ bool CPPEditorWidget::handleDocumentationComment(QKeyEvent *e)
if (!m_commentsSettings.m_leadingAsterisks) if (!m_commentsSettings.m_leadingAsterisks)
return false; return false;
const QString &text = cursor.block().text(); // We continue the comment if the cursor is after a comment's line asterisk and if
const int length = text.length(); // there's no asterisk immediately after the cursor (that would already be considered
// a leading asterisk).
int offset = 0; int offset = 0;
for (; offset < length; ++offset) { const int blockPos = cursor.positionInBlock();
const QChar &current = text.at(offset); const QString &text = cursor.block().text();
if (!current.isSpace()) for (; offset < blockPos; ++offset) {
if (!text.at(offset).isSpace())
break; break;
} }
if (offset < length
if (offset < blockPos
&& (text.at(offset) == QLatin1Char('*') && (text.at(offset) == QLatin1Char('*')
|| (offset < length - 1 || (offset < blockPos - 1
&& text.at(offset) == QLatin1Char('/') && text.at(offset) == QLatin1Char('/')
&& text.at(offset + 1) == QLatin1Char('*')))) { && text.at(offset + 1) == QLatin1Char('*')))) {
QString newLine(QLatin1Char('\n')); int followinPos = blockPos;
newLine.append(QString(offset, QLatin1Char(' '))); for (; followinPos < text.length(); ++followinPos) {
if (text.at(offset) == QLatin1Char('/')) { if (!text.at(followinPos).isSpace())
newLine.append(QLatin1String(" *")); break;
} else { }
int start = offset; if (followinPos == text.length()
while (offset < length && text.at(offset) == QLatin1Char('*')) || text.at(followinPos) != QLatin1Char('*')) {
++offset; QString newLine(QLatin1Char('\n'));
newLine.append(QString(offset - start, QLatin1Char('*'))); newLine.append(QString(offset, QLatin1Char(' ')));
if (text.at(offset) == QLatin1Char('/')) {
newLine.append(QLatin1String(" *"));
} else {
int start = offset;
while (offset < blockPos && text.at(offset) == QLatin1Char('*'))
++offset;
newLine.append(QString(offset - start, QLatin1Char('*')));
}
cursor.insertText(newLine);
e->accept();
return true;
} }
cursor.insertText(newLine);
e->accept();
return true;
} }
} }