Closes #25
This commit is contained in:
1 parent
c43222939f
commit
a258abf7be
7 files changed
+148
-5
No files matched your search
@@ -19,6 +19,35 @@
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
// Attribute statements end at a semicolon outside quoted text.
|
||||
void ReadAttributeLines(std::ifstream &input, std::string &statement,
|
||||
std::size_t &lineNumber) {
|
||||
bool inQuote = false;
|
||||
bool escaped = false;
|
||||
std::string part = statement;
|
||||
for (;;) {
|
||||
for (const char character: part) {
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
} else if (inQuote && character == '\\') {
|
||||
escaped = true;
|
||||
} else if (character == '"') {
|
||||
inQuote = !inQuote;
|
||||
} else if (!inQuote && character == ';') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!std::getline(input, part))
|
||||
return;
|
||||
++lineNumber;
|
||||
if (!part.empty() && part.back() == '\r')
|
||||
part.pop_back();
|
||||
statement += '\n';
|
||||
statement += part;
|
||||
escaped = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Read through the closing unescaped quote, preserving comment whitespace.
|
||||
void ReadCommentLines(std::ifstream &input, std::string &statement,
|
||||
std::size_t &lineNumber) {
|
||||
@@ -112,6 +141,9 @@ DbcParseResult DbcParser::ParseFileWithDiagnostics(const std::string &filePath)
|
||||
if (keyword == "CM_") {
|
||||
line = rawLine;
|
||||
ReadCommentLines(input, line, lineNumber);
|
||||
} else if (keyword == "BA_DEF_" || keyword == "BA_DEF_DEF_" || keyword == "BA_") {
|
||||
line = rawLine.substr(rawLine.find(keyword));
|
||||
ReadAttributeLines(input, line, lineNumber);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user