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,26 +2332,36 @@ 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('*')))) {
int followinPos = blockPos;
for (; followinPos < text.length(); ++followinPos) {
if (!text.at(followinPos).isSpace())
break;
}
if (followinPos == text.length()
|| text.at(followinPos) != QLatin1Char('*')) {
QString newLine(QLatin1Char('\n')); QString newLine(QLatin1Char('\n'));
newLine.append(QString(offset, QLatin1Char(' '))); newLine.append(QString(offset, QLatin1Char(' ')));
if (text.at(offset) == QLatin1Char('/')) { if (text.at(offset) == QLatin1Char('/')) {
newLine.append(QLatin1String(" *")); newLine.append(QLatin1String(" *"));
} else { } else {
int start = offset; int start = offset;
while (offset < length && text.at(offset) == QLatin1Char('*')) while (offset < blockPos && text.at(offset) == QLatin1Char('*'))
++offset; ++offset;
newLine.append(QString(offset - start, QLatin1Char('*'))); newLine.append(QString(offset - start, QLatin1Char('*')));
} }
@@ -2360,6 +2370,7 @@ bool CPPEditorWidget::handleDocumentationComment(QKeyEvent *e)
return true; return true;
} }
} }
}
return false; return false;
} }