Commit c950593c authored by Ahmad Samir's avatar Ahmad Samir

Port away from QRegExp

Some instances were replaced by QRegularExpression, whereas others were
replaced with QString manipulation.
parent ca6e58bc
......@@ -34,12 +34,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef HAVE_PCIUTILS
#include "kpci.h"
#endif //HAVE_PCIUTILS
#include <QRegExp>
#include <QFile>
#include <KLocalizedString>
#include <QFontDatabase>
#include <algorithm>
#define INFO_IRQ "/proc/interrupts"
#define INFO_DMA "/proc/dma"
......@@ -109,12 +110,18 @@ bool GetInfo_DMA(QTreeWidget* tree) {
line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
QRegExp rx(QStringLiteral("^\\s*(\\S+)\\s*:\\s*(\\S+)"));
if (-1 != rx.indexIn(line)) {
QStringList list;
list << rx.cap(1) << rx.cap(2);
new QTreeWidgetItem(tree, list);
// line is e.g. " 4: cascade"
QStringList list = line.split(QLatin1Char(':'), Qt::KeepEmptyParts, Qt::CaseInsensitive);
if (list.size() != 2) {
continue;
}
std::for_each(list.begin(), list.end(), [](QString &str) {
str = str.trimmed();
});
new QTreeWidgetItem(tree, list);
}
line = stream.readLine();
}
......
......@@ -23,7 +23,6 @@
#include "opengl.h"
#include <QRegExp>
#include <QFile>
#include <QTextStream>
#include <QProcess>
......@@ -256,12 +255,12 @@ static QVector<DriInfo> get_dri_devices()
QString line;
for (int i=2; i<=6; i++) {
line = pci_info[i];
line.remove(QRegExp("[^:]*:[ ]*"));
line = line.mid(line.indexOf(QLatin1Char(':')) + 1).simplified();
switch (i) {
case 2: it->vendor = line.simplified(); break;
case 3: it->device = line.simplified(); break;
case 4: it->subvendor = line.simplified(); break;
case 6: it->rev = line.simplified(); break;
case 2: it->vendor = line; break;
case 3: it->device = line; break;
case 4: it->subvendor = line; break;
case 6: it->rev = line; break;
}
}
} else {
......
......@@ -18,7 +18,7 @@
#include <QFile>
#include <QDir>
#include <QRegExp>
#include <QRegularExpression>
#include <KLocalizedString>
#include <KMessageBox>
......@@ -253,7 +253,8 @@ bool USBDevice::parse(const QString &fname) {
// read in the device infos
USBDevice *device = nullptr;
int start=0, end;
result.remove(QRegExp(QStringLiteral("^\n")));
const QString orig = result;
result.remove(QRegularExpression(QStringLiteral("^\n")));
while ((end = result.indexOf(QLatin1Char('\n'), start)) > 0)
{
QString line = result.mid(start, end-start);
......@@ -274,13 +275,17 @@ bool USBDevice::parseSys(const QString &dname) {
d.setNameFilters(QStringList() << QStringLiteral("usb*"));
const QStringList list = d.entryList();
const int length = QStringLiteral("usb").size();
for (QStringList::const_iterator it = list.constBegin(), total = list.constEnd(); it != total; ++it) {
USBDevice* device = new USBDevice();
int bus = 0;
QRegExp bus_reg(QStringLiteral("[a-z]*([0-9]+)"));
if (bus_reg.indexIn(*it) != -1)
bus = bus_reg.cap(1).toInt();
bool ok = false;
const int num = it->midRef(it->lastIndexOf(QLatin1String("usb")) + length).toInt(&ok);
if (ok) {
bus = num;
}
device->parseSysDir(bus, 0, 0, d.absolutePath() + QLatin1Char('/') + *it);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment