This commit is contained in:
deeaitch committed 2026-10-05 18:37:20 -04:00
1 parent 8d82b13dad
commit b91cf4aae5
21 files changed
+1165 -1146

No files matched your search

+41 -41
View File
@@ -12,59 +12,59 @@
#include "dbc_parser.h"
#include "dbc_statement_handler.h"
#include <cctype>
#include <fstream>
#include <stdexcept>
#include <cctype>
namespace {
/**
/**
* @brief Remove leading and trailing spaces.
* @param text Input text.
* @return Trimmed text.
*/
std::string TrimText (const std::string &text) {
std::string::size_type begin = 0U;
while ((begin < text.size()) &&
std::isspace (static_cast<unsigned char> (text[begin])))
++begin;
std::string TrimText(const std::string &text) {
std::string::size_type begin = 0U;
while ((begin < text.size()) &&
std::isspace(static_cast<unsigned char>(text[begin])))
++begin;
std::string::size_type end = text.size();
while ((end > begin) &&
std::isspace (static_cast<unsigned char> (text[end - 1U])))
--end;
std::string::size_type end = text.size();
while ((end > begin) &&
std::isspace(static_cast<unsigned char>(text[end - 1U])))
--end;
return text.substr (begin, end - begin);
}
}
DbcDatabase DbcParser::ParseFile (const std::string &filePath) const {
std::ifstream input (filePath.c_str());
if (!input.is_open())
throw std::runtime_error ("Failed to open DBC file: " + filePath);
DbcDatabase database;
DbcParseContext context {database, nullptr};
const DbcStatementDispatcher dispatcher;
std::size_t lineNumber = 0U;
std::string line;
while (std::getline (input, line)) {
++lineNumber;
line = Trim (line);
if (line.empty())
continue;
try {
dispatcher.Dispatch (line, context);
} catch (const std::exception &error) {
throw std::runtime_error (filePath + ":" + std::to_string (lineNumber) +
": " + error.what());
return text.substr(begin, end - begin);
}
}
}// namespace
return database;
DbcDatabase DbcParser::ParseFile(const std::string &filePath) const {
std::ifstream input(filePath.c_str());
if (!input.is_open())
throw std::runtime_error("Failed to open DBC file: " + filePath);
DbcDatabase database;
DbcParseContext context{database, nullptr};
const DbcStatementDispatcher dispatcher;
std::size_t lineNumber = 0U;
std::string line;
while (std::getline(input, line)) {
++lineNumber;
line = Trim(line);
if (line.empty())
continue;
try {
dispatcher.Dispatch(line, context);
} catch (const std::exception &error) {
throw std::runtime_error(filePath + ":" + std::to_string(lineNumber) +
": " + error.what());
}
}
return database;
}
std::string DbcParser::Trim (const std::string &text) {
return TrimText (text);
std::string DbcParser::Trim(const std::string &text) {
return TrimText(text);
}