QTextDocument QRegExp search cleanup

Code cleanup and improvement

Change-Id: Id4eac84dd31976797403c9acfa40c8d3337c6988
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Samuel Gaist 2014-11-29 00:26:49 +01:00 committed by Konstantin Ritt
parent a3640ac260
commit 1add31da9e

View File

@ -1388,13 +1388,11 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
} }
} }
//we have a hit, return the cursor for that. //we have a hit, return the cursor for that.
break; *cursor = QTextCursor(block.docHandle(), block.position() + idx);
cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor);
return true;
} }
if (idx == -1) return false;
return false;
*cursor = QTextCursor(block.docHandle(), block.position() + idx);
cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor);
return true;
} }
/*! /*!
@ -1430,17 +1428,15 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
QTextCursor cursor; QTextCursor cursor;
QTextBlock block = d->blocksFind(pos); QTextBlock block = d->blocksFind(pos);
int blockOffset = pos - block.position();
if (!(options & FindBackward)) { if (!(options & FindBackward)) {
int blockOffset = qMax(0, pos - block.position());
while (block.isValid()) { while (block.isValid()) {
if (findInBlock(block, expr, blockOffset, options, &cursor)) if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor; return cursor;
blockOffset = 0;
block = block.next(); block = block.next();
blockOffset = 0;
} }
} else { } else {
int blockOffset = pos - block.position();
while (block.isValid()) { while (block.isValid()) {
if (findInBlock(block, expr, blockOffset, options, &cursor)) if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor; return cursor;