Commit 8499f74b authored by Laurent Montel's avatar Laurent Montel 😁

Add support for default categories

parent 6c1cfe15
......@@ -49,11 +49,11 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine_data()
QTest::newRow("comment-2") << QStringLiteral("#log linux") << QString() << QString() << QString() << false;
QTest::newRow("validLineWithParentheses") << QStringLiteral("log linux (foo)") << QStringLiteral("linux (foo)") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineWithParenthesesAndCategories") << QStringLiteral("log linux (foo) [WARNING]") << QStringLiteral("linux (foo)") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineWithParenthesesAndCategories") << QStringLiteral("log linux (foo) [WARNING]") << QStringLiteral("linux (foo)") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories") << QStringLiteral("log linux [WARNING]") << QStringLiteral("linux") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineCategories2") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineCategories3") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineCategories") << QStringLiteral("log linux [WARNING]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories2") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories3") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("linewithcomment") << QStringLiteral("log linux#comment about linux") << QStringLiteral("linux") << QStringLiteral("log") << QString() << true;
}
......@@ -67,6 +67,7 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine()
KdeLoggingCategory result;
result.description = description;
result.logName = logname;
result.defaultCategory = defaultCategory;
const KdeLoggingCategory cat = KDebugSettingsUtil::parseLineKdeLoggingCategory(input);
if (cat != result) {
qDebug() << "Generated category " << cat;
......
......@@ -100,6 +100,7 @@ KdeLoggingCategory KDebugSettingsUtil::parseLineKdeLoggingCategory(QString line)
#else
QString logName;
QString description;
QString defaultCategory;
static const QRegularExpression regularExpressionUser(QStringLiteral("^([\\w._-]+)\\s*(.*)$"));
QRegularExpressionMatch match = regularExpressionUser.match(line);
if (match.hasMatch()) {
......@@ -109,20 +110,22 @@ KdeLoggingCategory KDebugSettingsUtil::parseLineKdeLoggingCategory(QString line)
}
static const QRegularExpression regularExpressionDefaultCategory(QStringLiteral("^(.*)\\s+\\[(.*)\\]$"));
QRegularExpressionMatch match2 = regularExpressionDefaultCategory.match(description);
QString defaultCategoryCaptured;
if (match.hasMatch()) {
const QString descriptionCaptured = match2.captured(1);
const QString defaultCategory = match2.captured(2);
if (!descriptionCaptured.isEmpty() && !defaultCategory.isEmpty()) {
defaultCategoryCaptured = match2.captured(2);
if (!descriptionCaptured.isEmpty() && !defaultCategoryCaptured.isEmpty()) {
description = descriptionCaptured;
qDebug() << " match.captured(1);" << match2.captured(1);
qDebug() << " match.captured(2);" << match2.captured(2);
defaultCategory = defaultCategoryCaptured;
//qDebug() << " match.captured(1);" << descriptionCaptured;
//qDebug() << " match.captured(2);" << defaultCategoryCaptured;
}
}
#endif
category.logName = logName;
category.description = description;
//TODO add default categories ?
category.defaultCategory = defaultCategoryCaptured;
return category;
}
......
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