Avoid using a QRegExp for trivial replacements
It's slow and we want to get rid of it. In this case, it's just as easy to do the replacing manually using a small loop. Task-number: QTBUG-72587 Change-Id: I32e1cc89642bc0e5b6f500d072960cd8871e0684 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
40f28b1a8a
commit
1e27db6c20
@ -49,7 +49,6 @@
|
||||
#include <qelapsedtimer.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qrandom.h>
|
||||
#include <qregexp.h>
|
||||
#include <qwineventnotifier.h>
|
||||
#include <private/qsystemlibrary_p.h>
|
||||
#include <private/qthread_p.h>
|
||||
@ -398,7 +397,17 @@ static QString qt_create_commandline(const QString &program, const QStringList &
|
||||
for (int i=0; i<arguments.size(); ++i) {
|
||||
QString tmp = arguments.at(i);
|
||||
// Quotes are escaped and their preceding backslashes are doubled.
|
||||
tmp.replace(QRegExp(QLatin1String("(\\\\*)\"")), QLatin1String("\\1\\1\\\""));
|
||||
int index = tmp.indexOf(QLatin1Char('"'));
|
||||
while (index >= 0) {
|
||||
// Escape quote
|
||||
tmp.insert(index++, QLatin1Char('\\'));
|
||||
// Double preceding backslashes (ignoring the one we just inserted)
|
||||
for (int i = index - 2 ; i >= 0 && tmp.at(i) == QLatin1Char('\\') ; --i) {
|
||||
tmp.insert(i, QLatin1Char('\\'));
|
||||
index++;
|
||||
}
|
||||
index = tmp.indexOf(QLatin1Char('"'), index + 1);
|
||||
}
|
||||
if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) {
|
||||
// The argument must not end with a \ since this would be interpreted
|
||||
// as escaping the quote -- rather put the \ behind the quote: e.g.
|
||||
|
Loading…
Reference in New Issue
Block a user