c-coderdbc icon indicating copy to clipboard operation
c-coderdbc copied to clipboard

Incorrect handling multiline VAL_

Open WojciechJasko-BB opened this issue 6 months ago • 0 comments

When VAL_ in DBC is splited in multiple lines, then generated comment is invalid (it does not compile).

For example this line:

VAL_ 11111 Bat_Status 0 "Battery level above 2.1V
" 1 " Low Battery(below 2.1V)
" ;

will produce:

  uint8_t Bat_Status : 1;   //      Bits= 1

  //  0 : "Battery level above 2.1V
"
  //  1 : " Low Battery(below 2.1V)
"

To solve that I modified DbcLineParser::ParseValTableLine method to drop all new lines within valueline

bool DbcLineParser::ParseValTableLine(Comment_t* comm, const std::string& line, ValTable_t& vtab)
{
  bool ret = false;

  if (line.size() > 0)
  {
    if (line.find("VAL_ ") == 0)
    {
      valueline.clear();
      valueline = line;
    }
    else if (valueline.size() > 0)
    {
      valueline += line;
    }

    // check if the current line is last
    if (valueline.size() > 0 && line.back() == ';')
    {
      std::replace(valueline.begin(), valueline.end(), '\n', ' ');
      std::replace(valueline.begin(), valueline.end(), '\r', ' ');

WojciechJasko-BB avatar Aug 22 '24 13:08 WojciechJasko-BB