Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 203fb9f4 authored by Laurent Montel's avatar Laurent Montel 😁

Start to use QRegularExpression

parent 74c0ca9f
......@@ -21,6 +21,7 @@
#include "kdebugsettingutiltest.h"
#include "../src/kdebugsettingsutil.h"
#include <qtest.h>
#include <QDebug>
KDebugSettingUtilTest::KDebugSettingUtilTest(QObject *parent)
: QObject(parent)
......@@ -40,6 +41,7 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine_data()
QTest::addColumn<QString>("logname");
QTest::addColumn<bool>("valid");
QTest::newRow("empty") << QString() << QString() << QString() << false;
QTest::newRow("validLine") << QStringLiteral("log linux") << QStringLiteral("linux") << QStringLiteral("log") << true;
QTest::newRow("validLinewithspace") << QStringLiteral(" log linux ") << QStringLiteral("linux") << QStringLiteral("log") << true;
QTest::newRow("comment") << QStringLiteral("#log linux ") << QString() << QString() << false;
......@@ -60,6 +62,10 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine()
result.description = description;
result.logName = logname;
const KdeLoggingCategory cat = KDebugSettingsUtil::parseLineKdeLoggingCategory(input);
if (cat != result) {
qDebug() << " cat " << cat;
qDebug() << " result !: "<<result;
}
QCOMPARE(cat, result);
QCOMPARE(cat.isValid(), valid);
}
......
......@@ -22,6 +22,7 @@
#include "kdebugsettings_debug.h"
#include <QFile>
#include <QFileInfo>
#include <QRegularExpression>
RenameCategory KDebugSettingsUtil::parseRenameCategory(QString line)
{
......@@ -90,10 +91,22 @@ KdeLoggingCategory KDebugSettingsUtil::parseLineKdeLoggingCategory(QString line)
qCWarning(KDEBUGSETTINGS_LOG) << "No space:" << line << endl;
return category;
}
#if 1
const QString logName = line.left(space);
const QString description = line.mid(space).simplified();
#else
QString logName;
QString description;
static const QRegularExpression regularExpressionUser(QStringLiteral("^(.*)\\s+(.*)$"));
QRegularExpressionMatch match = regularExpressionUser.match(line);
if (match.hasMatch()) {
logName = match.captured(1);
description = match.captured(2);
qDebug() << " logName"<<logName<<" description " << description << " line " << line;
}
#endif
category.logName = logName;
category.description = description;
//TODO add default categories ?
......
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