QTextDocument QRegularExpression search cleanup

Code cleanup and improvement

Change-Id: I04109e6eaa24e90e24ba89957adca32281d077dc
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Samuel Gaist 2014-11-29 00:28:10 +01:00 committed by Konstantin Ritt
parent 517da68893
commit a3640ac260

View File

@ -1516,13 +1516,11 @@ static bool findInBlock(const QTextBlock &block, const QRegularExpression &expre
}
}
//we have a hit, return the cursor for that.
break;
*cursor = QTextCursor(block.docHandle(), block.position() + idx);
cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
return true;
}
if (idx == -1)
return false;
*cursor = qMove(QTextCursor(block.docHandle(), block.position() + idx));
cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
return true;
return false;
}
/*!
@ -1557,17 +1555,16 @@ QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFl
QTextCursor cursor;
QTextBlock block = d->blocksFind(pos);
int blockOffset = pos - block.position();
if (!(options & FindBackward)) {
int blockOffset = qMax(0, pos - block.position());
while (block.isValid()) {
if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;
blockOffset = 0;
block = block.next();
blockOffset = 0;
}
} else {
int blockOffset = pos - block.position();
while (block.isValid()) {
if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;