Skip to content

Commit dc48817

Browse files
committed
- signals can also contain special characters: SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3
1 parent 3951a7c commit dc48817

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/dbc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const auto offsetScalePattern = std::string("\\(") + scalePattern + "\\," + offs
2020
const auto minPattern = floatPattern;
2121
const auto maxPattern = floatPattern;
2222
const auto minMaxPattern = std::string("\\[") + minPattern + "\\|" + maxPattern + "\\]";
23-
const auto unitPattern = "\"(\\w*)\""; // Random string
23+
const auto unitPattern = "\"(.*)\""; // Random string
2424
const auto receiverPattern = "([\\w\\,]+|Vector__XXX)*";
2525
const auto whiteSpace = "\\s";
2626

test/test_dbc.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,26 @@ TEST_CASE("Testing negative values") {
103103
REQUIRE(signal.max == 32767);
104104
}
105105
}
106+
107+
108+
TEST_CASE("Special characters in unit") {
109+
const auto* filename = std::tmpnam(NULL);
110+
111+
auto* file = std::fopen(filename, "w");
112+
CHECK(file);
113+
114+
std::fputs(PRIMITIVE_DBC.c_str(), file);
115+
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
116+
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)", file);
117+
std::fclose(file);
118+
119+
auto parser = libdbc::DbcParser();
120+
parser.parse_file(std::string(filename));
121+
122+
REQUIRE(parser.get_messages().size() == 1);
123+
REQUIRE(parser.get_messages().at(0).signals.size() == 1);
124+
{
125+
const auto signal = parser.get_messages().at(0).signals.at(0);
126+
REQUIRE(signal.unit.compare("Km/h") == 0);
127+
}
128+
}

0 commit comments

Comments
 (0)