test: migrate QPrinterInfo test to QRegularExpression
This is part of the migration of qtbase from QRexExp to QRegularExpression. Task-number: QTBUG-72587 Change-Id: I949479066e114af0af85b6e62d90fd56b9c80077 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
2d72bf6019
commit
5174c8abae
@ -94,17 +94,16 @@ QString tst_QPrinterInfo::getDefaultPrinterFromSystem()
|
|||||||
command << "lpstat" << "-d";
|
command << "lpstat" << "-d";
|
||||||
QString output = getOutputFromCommand(command);
|
QString output = getOutputFromCommand(command);
|
||||||
|
|
||||||
QRegExp noDefaultReg("[^:]*no .*default");
|
QRegularExpression noDefaultReg("[^:]*no .*default");
|
||||||
int pos = noDefaultReg.indexIn(output);
|
QRegularExpressionMatch match;
|
||||||
if (pos >= 0) {
|
match = noDefaultReg.match(output);
|
||||||
|
if (match.hasMatch())
|
||||||
return QString();
|
return QString();
|
||||||
}
|
|
||||||
|
|
||||||
QRegExp defaultReg("default.*: *([a-zA-Z0-9_-]+)");
|
QRegularExpression defaultReg("default.*: *([a-zA-Z0-9_-]+)");
|
||||||
defaultReg.indexIn(output);
|
match = defaultReg.match(output);
|
||||||
printer = defaultReg.cap(1);
|
printer = match.captured(1);
|
||||||
#endif // Q_OS_UNIX
|
#endif // Q_OS_UNIX
|
||||||
|
|
||||||
return printer;
|
return printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +120,12 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem()
|
|||||||
QString output = getOutputFromCommand(command);
|
QString output = getOutputFromCommand(command);
|
||||||
QStringList list = output.split(QChar::fromLatin1('\n'));
|
QStringList list = output.split(QChar::fromLatin1('\n'));
|
||||||
|
|
||||||
QRegExp reg("^[Pp]rinter ([.a-zA-Z0-9-_@]+)");
|
QRegularExpression reg("^[Pp]rinter ([.a-zA-Z0-9-_@]+)");
|
||||||
|
QRegularExpressionMatch match;
|
||||||
for (int c = 0; c < list.size(); ++c) {
|
for (int c = 0; c < list.size(); ++c) {
|
||||||
if (reg.indexIn(list[c]) >= 0) {
|
match = reg.match(list[c]);
|
||||||
QString printer = reg.cap(1);
|
if (match.hasMatch()) {
|
||||||
|
QString printer = match.captured(1);
|
||||||
ans << printer;
|
ans << printer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user