Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and Improve RegEx Replace feature. #565

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions qdlt/qdltexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void QDltExporter::writeCSVLine(int index, QFile *to, QDltMsg msg)
text += escapeCSVValue(QString("%1").arg(msg.getModeString())).append(delimiter);
text += escapeCSVValue(QString("%1").arg(msg.getNumberOfArguments())).append(delimiter);
QString payload = msg.toStringPayload().simplified().remove(QChar::Null);
if(from) from->applyRegExString(payload);
if(from) from->applyRegExString(msg,payload);
text += escapeCSVValue(payload);
text += "\n";

Expand Down Expand Up @@ -283,7 +283,7 @@ bool QDltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &bu
text += " ";
}
QString payload = msg.toStringPayload().simplified().remove(QChar::Null);
if(from) from->applyRegExString(payload);
if(from) from->applyRegExString(msg,payload);
text += payload;
text += "\n";
try
Expand Down Expand Up @@ -331,7 +331,7 @@ bool QDltExporter::exportMsg(unsigned long int num, QDltMsg &msg, QByteArray &bu
else
text += "|" + QString("%1.%2").arg(msg.getTimeString()).arg(msg.getMicroseconds(),6,10,QLatin1Char('0'));
QString payload = msg.toStringPayload().simplified().remove(QChar::Null);
if(from) from->applyRegExString(payload);
if(from) from->applyRegExString(msg,payload);
text += "|" + QString("%1.%2").arg(msg.getTimestamp()/10000).arg(msg.getTimestamp()%10000,4,10,QLatin1Char('0')) +
"|" + msg.getEcuid() +
"|" + msg.getApid() +
Expand Down Expand Up @@ -440,8 +440,9 @@ void QDltExporter::exportMessages(QDltFile *from, QFile *to, QDltPluginManager *
{
//FIXME: The following does not work for non verbose messages, must be fixed to enable RegEx for DLT Export again
//msg.setNumberOfArguments(msg.sizeArguments());
//if(from) from->applyRegExStringMsg(msg);
//msg.getMsg(buf,true);
bool isApplied = false;
if(from) isApplied = from->applyRegExStringMsg(msg);
if(isApplied) msg.getMsg(buf,true);
}

// export message
Expand Down
7 changes: 4 additions & 3 deletions qdlt/qdltfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,13 @@ void QDltFile::setIndexFilter(QVector<qint64> _indexFilter)
indexFilter = _indexFilter;
}

bool QDltFile::applyRegExString(QString &text)
bool QDltFile::applyRegExString(QDltMsg &msg,QString &text)
{
return filterList.applyRegExString(text);

return filterList.applyRegExString(msg,text);
}

bool QDltFile::applyRegExStringMsg(QDltMsg &msg)
{
{
return filterList.applyRegExStringMsg(msg);
}
2 changes: 1 addition & 1 deletion qdlt/qdltfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class QDLT_EXPORT QDltFile : public QDlt
//! Apply RegEx Replace to the string, if any active in the filters
/*!
*/
bool applyRegExString(QString &text);
bool applyRegExString(QDltMsg &msg,QString &text);

//! Apply RegEx Replace to the arguments of a message, if any active in the filters
/*!
Expand Down
6 changes: 3 additions & 3 deletions qdlt/qdltfilterlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ QString QDltFilterList::checkMarker(QDltMsg &msg)

#endif

bool QDltFilterList::applyRegExString(QString &text)
bool QDltFilterList::applyRegExString(QDltMsg &msg,QString &text)
{
QDltFilter *filter;
bool result = false;
Expand All @@ -133,7 +133,7 @@ bool QDltFilterList::applyRegExString(QString &text)
{
filter = pfilters[numfilter];

if(filter->enableFilter && filter->enableRegexSearchReplace)
if(filter->enableFilter && filter->enableRegexSearchReplace && filter->match(msg))
{
text.replace(QRegularExpression(filter->regex_search), filter->regex_replace);
result = true;
Expand All @@ -151,7 +151,7 @@ bool QDltFilterList::applyRegExStringMsg(QDltMsg &msg)
{
filter = pfilters[numfilter];

if(filter->enableFilter && filter->enableRegexSearchReplace)
if(filter->enableFilter && filter->enableRegexSearchReplace && filter->match(msg))
{
for(int num=0;num<msg.getNumberOfArguments();num++)
{
Expand Down
2 changes: 1 addition & 1 deletion qdlt/qdltfilterlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class QDLT_EXPORT QDltFilterList
//! Apply RegEx Replace to the string, if any active in the filters.
/*!
*/
bool applyRegExString(QString &text);
bool applyRegExString(QDltMsg &msg,QString &text);

//! Apply RegEx Replace to the argumnets of a message, if any active in the filters.
/*!
Expand Down
5 changes: 3 additions & 2 deletions src/searchtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ QVariant SearchTableModel::data(const QModelIndex &index, int role) const
case FieldNames::Payload:
/* display payload */
visu_data = msg.toStringPayload().simplified().remove(QChar::Null);
if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool()))
if(qfile) qfile->applyRegExString(msg,visu_data);
/*if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool()))
{
for(int num = 0; num < project->filter->topLevelItemCount (); num++) {
FilterItem *item = (FilterItem*)project->filter->topLevelItem(num);
if(item->checkState(0) == Qt::Checked && item->filter.enableRegexSearchReplace) {
visu_data.replace(QRegularExpression(item->filter.regex_search), item->filter.regex_replace);
}
}
}
}*/
return visu_data;
case FieldNames::MessageId:
return QString::asprintf(project->settings->msgIdFormat.toUtf8(),msg.getMessageId());
Expand Down
6 changes: 3 additions & 3 deletions src/tablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ TableModel::TableModel(const QString & /*data*/, QObject *parent)
}
/* display payload */
visu_data = msg.toStringPayload().simplified().remove(QChar::Null);

if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool()))
if(qfile) qfile->applyRegExString(msg,visu_data);
/*if((QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool()))
{
for(int num = 0; num < project->filter->topLevelItemCount (); num++) {
FilterItem *item = (FilterItem*)project->filter->topLevelItem(num);
if(item->checkState(0) == Qt::Checked && item->filter.enableRegexSearchReplace) {
visu_data.replace(QRegularExpression(item->filter.regex_search), item->filter.regex_replace);
}
}
}
}*/

/* limit size of string to 1000 characters to speed up scrolling */
if(visu_data.size()>1000)
Expand Down