diff --git a/src/parser/dbc/DbcParser.cpp b/src/parser/dbc/DbcParser.cpp index f12f119..98ead01 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()) { @@ -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, "edStr, skipWhitespace); - if (ok && quotedStr.length()>=2) { - *str = quotedStr.mid(1, quotedStr.length()-2); - return true; - } else { - return false; + if (expectData(tokens, dbc_tok_string, "edStr, 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) diff --git a/src/parser/dbc/DbcTokens.cpp b/src/parser/dbc/DbcTokens.cpp index 5a77dbe..3d78c9a 100644 --- a/src/parser/dbc/DbcTokens.cpp +++ b/src/parser/dbc/DbcTokens.cpp @@ -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; + } } diff --git a/src/parser/dbc/DbcTokens.h b/src/parser/dbc/DbcTokens.h index 4c7cfe4..af29b04 100644 --- a/src/parser/dbc/DbcTokens.h +++ b/src/parser/dbc/DbcTokens.h @@ -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 {