Don't use the QRegExp methods that modify the object [QtGui]

QRegExp matching methods modify the object, which we don't want to. In
particular, when we receive a QRegExp from the user or we store in a
context that might require thread-safety, make sure we make a copy
before using it.

QRegularExpression has no such shortcoming.

Task-number: QTBUG-25064
Change-Id: If119e06221ca99e57c5ad1a1d4cc6468e9f68c7b
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
This commit is contained in:
Thiago Macieira 2012-04-20 14:59:30 +02:00 committed by Qt by Nokia
parent fd7e1cef9c
commit 092118855b
3 changed files with 5 additions and 4 deletions

View File

@ -1281,7 +1281,7 @@ QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &fro
static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset,
QTextDocument::FindFlags options, QTextCursor &cursor)
{
const QRegExp expr(expression);
QRegExp expr(expression);
QString text = block.text();
text.replace(QChar::Nbsp, QLatin1Char(' '));

View File

@ -871,10 +871,11 @@ QRegExpValidator::~QRegExpValidator()
QValidator::State QRegExpValidator::validate(QString &input, int& pos) const
{
if (r.exactMatch(input)) {
QRegExp copy = r;
if (copy.exactMatch(input)) {
return Acceptable;
} else {
if (const_cast<QRegExp &>(r).matchedLength() == input.size()) {
if (copy.matchedLength() == input.size()) {
return Intermediate;
} else {
pos = input.size();

View File

@ -694,7 +694,7 @@ void PaintCommands::runCommand(const QString &scriptLine)
QString firstWord = scriptLine.section(QRegExp("\\s"), 0, 0);
QList<int> indices = s_commandHash.values(firstWord);
foreach(int idx, indices) {
const PaintCommandInfos &command = s_commandInfoTable.at(idx);
PaintCommandInfos command = s_commandInfoTable.at(idx);
if (command.regExp.indexIn(scriptLine) >= 0) {
(this->*(command.paintMethod))(command.regExp);
return;