Skip to content

Commit 2d84962

Browse files
committed
split signal regex into multiple variable to make it more readable
1 parent c246cdd commit 2d84962

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/dbc.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,54 @@
44

55
#include <regex>
66

7+
namespace {
8+
9+
const auto signalIdentifierPattern = "(SG_)";
10+
const auto namePattern = "(\\w+)";
11+
const auto bitStartPattern = "(\\d+)"; // Cannot be negative
12+
const auto lengthPattern = "(\\d+)"; // Cannot be negative
13+
const auto byteOrderPattern = "([0-1])";
14+
const auto signPattern = "(\\+|\\-)";
15+
const auto scalePattern = "(\\d+\\.?(\\d+)?)";
16+
const auto offsetPattern = "(-?\\d+\\.?(\\d+)?)"; // Can be negative
17+
const auto offsetScalePattern = std::string("\\(") + scalePattern + "\\," + offsetPattern + "\\)";
18+
const auto minPattern = "(-?\\d+\\.?(\\d+)?)";
19+
const auto maxPattern = "(-?\\d+\\.?(\\d+)?)";
20+
const auto minMaxPattern = std::string("\\[") + minPattern + "\\|" + maxPattern + "\\]";
21+
const auto unitPattern = "\"(\\w*)\"";
22+
const auto receiverPattern = "([\\w\\,]+|Vector__XXX)*";
23+
const auto whiteSpace = "\\s";
24+
25+
} // anonymous namespace
26+
727
namespace libdbc {
828

929
DbcParser::DbcParser() : version(""), nodes(),
1030
version_re("^(VERSION)\\s\"(.*)\""), bit_timing_re("^(BS_:)"),
1131
name_space_re("^(NS_)\\s\\:"), node_re("^(BU_:)\\s((?:[\\w]+?\\s?)*)"),
1232
message_re("^(BO_)\\s(\\d+)\\s(\\w+)\\:\\s(\\d+)\\s(\\w+|Vector__XXX)"),
1333
// NOTE: No multiplex support yet
14-
signal_re("\\s(SG_)\\s(\\w+)\\s\\:\\s(\\d+)\\|(\\d+)\\@(\\d+)(\\+|\\-)\\s\\((\\d+\\.?(\\d+)?)\\,(\\d+\\.?(\\d+)?)\\)\\s\\[(-?\\d+\\.?(\\d+)?)\\|(-?\\d+\\.?(\\d+)?)\\]\\s\"(\\w*)\"\\s([\\w\\,]+|Vector__XXX)*") {
34+
signal_re(std::string(whiteSpace) +
35+
signalIdentifierPattern +
36+
whiteSpace +
37+
namePattern +
38+
whiteSpace +
39+
"\\:" +
40+
whiteSpace +
41+
bitStartPattern +
42+
"\\|" +
43+
lengthPattern +
44+
"\\@" +
45+
byteOrderPattern +
46+
signPattern +
47+
whiteSpace +
48+
offsetScalePattern +
49+
whiteSpace +
50+
minMaxPattern +
51+
whiteSpace +
52+
unitPattern +
53+
whiteSpace +
54+
receiverPattern) {
1555

1656
}
1757

0 commit comments

Comments
 (0)