From 2ed6c7e37fa1b042d87a02c1a8c5e41e1a39d3ce Mon Sep 17 00:00:00 2001 From: luckyhacky Date: Fri, 13 Dec 2024 22:46:07 +0100 Subject: [PATCH] fix dbc parsing add char "J" - was missing in regexp string allow \" in comments - will be converted to "'" --- src/parser/dbc/DbcParser.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/parser/dbc/DbcParser.cpp b/src/parser/dbc/DbcParser.cpp index f12f119..a460ec7 100644 --- a/src/parser/dbc/DbcParser.cpp +++ b/src/parser/dbc/DbcParser.cpp @@ -51,7 +51,7 @@ bool DbcParser::parseFile(QFile *file, CanDb &candb) DbcToken *DbcParser::createNewToken(QChar ch, int line, int column) { - static const QString acceptableIdStartChars("ABCDEFGHIKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"); + static const QString acceptableIdStartChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"); static const QRegExp numberRegExp("^(\\d+(\\.\\d*)?(E[-+]?\\d*)?)$"); if (ch.isSpace()) { @@ -100,6 +100,8 @@ DbcParser::error_t DbcParser::tokenize(QFile *file, DbcParser::DbcTokenList &tok DbcToken *currentToken = 0; int line = 1; int column = 0; + QString s; + QChar ch; error_t retval = err_ok; @@ -107,10 +109,10 @@ DbcParser::error_t DbcParser::tokenize(QFile *file, DbcParser::DbcTokenList &tok in.setCodec("ISO 8859-1"); while (true) { - QString s = in.read(1); + s = in.read(1); if (s.isEmpty()) { break; } - QChar ch = s[0]; + ch = s[0]; if (ch=='\n') { line++; @@ -119,6 +121,19 @@ DbcParser::error_t DbcParser::tokenize(QFile *file, DbcParser::DbcTokenList &tok column++; } + // handle escape of " - need to replace it to ' + if(ch=='\\') { + s = in.read(1); + ch = s[0]; + if(ch!='"') { + retval = err_tokenize_error; + _errorColumn = column; + _errorLine = line; + break; + } + ch = '\''; + } + if (currentToken) { if (!currentToken->appendChar(ch)) { tokens.append(currentToken);