QTextDocument QRegularExpression search cleanup
Code cleanup and improvement Change-Id: I04109e6eaa24e90e24ba89957adca32281d077dc Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
parent
517da68893
commit
a3640ac260
@ -1516,13 +1516,11 @@ static bool findInBlock(const QTextBlock &block, const QRegularExpression &expre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//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() + match.capturedLength(), QTextCursor::KeepAnchor);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (idx == -1)
|
return false;
|
||||||
return false;
|
|
||||||
*cursor = qMove(QTextCursor(block.docHandle(), block.position() + idx));
|
|
||||||
cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1557,17 +1555,16 @@ QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFl
|
|||||||
|
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user