Skip to content
Open
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
18 changes: 11 additions & 7 deletions src/parser/dbc/DbcParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -265,13 +265,17 @@ bool DbcParser::expectIdentifier(DbcParser::DbcTokenList &tokens, QString *id, b
bool DbcParser::expectString(DbcParser::DbcTokenList &tokens, QString *str, bool skipWhitespace)
{
QString quotedStr;
bool ok = expectData(tokens, dbc_tok_string, &quotedStr, skipWhitespace);
if (ok && quotedStr.length()>=2) {
*str = quotedStr.mid(1, quotedStr.length()-2);
return true;
} else {
return false;
if (expectData(tokens, dbc_tok_string, &quotedStr, skipWhitespace)) {
// Remove any escape characters
quotedStr.replace(QRegExp("\\\\(.)"), "\\1");

// Remove leading and trailing quotes
if (quotedStr.length() >=2 ) {
*str = quotedStr.mid(1, quotedStr.length()-2);
return true;
}
}
return false;
}

bool DbcParser::expectNumber(DbcParser::DbcTokenList &tokens, QString *str, bool skipWhitespace)
Expand Down
33 changes: 25 additions & 8 deletions src/parser/dbc/DbcTokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,36 @@ bool DbcIdentifierToken::acceptsChar(QChar ch)


DbcStringToken::DbcStringToken(int line, int column)
: DbcToken(line, column, dbc_tok_string)
: DbcToken(line, column, dbc_tok_string),
_done(false),
_escape(false)
{
}

/// Accept strings surrounded by '"", including '\'-escaped characters
bool DbcStringToken::acceptsChar(QChar ch)
{
if (_data.isEmpty()) {
return (ch=='"');
} else if (_data.length()<2) {
return true;
} else {
return !_data.endsWith('"');
}
if (_done) {
return false;
}

if(_data.isEmpty()) {
// Start of string must be '"'
return (ch == '"');
} else {
// Accept anything until an unescaped '"'
if (_escape) {
_escape = false;
} else {
if (ch == '\\') {
_escape = true;
}
if (ch == '"') {
_done = true;
}
}
return true;
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/parser/dbc/DbcTokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class DbcStringToken : public DbcToken {
public:
DbcStringToken(int line, int column);
virtual bool acceptsChar(QChar ch);
private:
bool _done;
bool _escape;
};

class DbcRegExpToken : public DbcToken {
Expand Down