Skip to content

Commit afc43c0

Browse files
committed
Fixes decimal number parsing bug
1 parent 24fdb1c commit afc43c0

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ if(BUILD_TESTING)
8989

9090
add_test(NAME cpc-checkframe-big-endian-3
9191
COMMAND can-parse checkframe 1800 dbc-files/big-endian-1.dbc)
92+
93+
add_test(NAME cpc-checkframe-decimal-scale-1
94+
COMMAND can-parse checkframe dbc-files/decimal-scale-1.dbc)
9295
endif()

src/parsing/Tokenizer.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ bool isSeparator(char c) {
1414
c == ')' || c == '(' || c == ',' || c == ';';
1515
}
1616

17+
bool isAny(char c, const std::string &chars) {
18+
return chars.find(c) != std::string::npos;
19+
}
20+
1721
bool isDigit(char c) {
1822
return std::isdigit((unsigned char)c);
1923
}
@@ -243,7 +247,7 @@ std::string Tokenizer::parseNumber(bool& is_float) {
243247
char currentChar = getNextChar();
244248
is_float = false;
245249

246-
while (isDigit(currentChar) && !isEOF(currentChar)) {
250+
while ((isDigit(currentChar) || isAny(currentChar,".e"))&& !isEOF(currentChar)) {
247251
result += currentChar;
248252
currentChar = getNextChar();
249253

tests/dbc-files/decimal-scale-1.dbc

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
VERSION "SingleFrame1.dbc"
2+
3+
NS_ :
4+
CM_
5+
BA_DEF_
6+
BA_
7+
VAL_
8+
CAT_DEF_
9+
CAT_
10+
FILTER
11+
BA_DEF_DEF_
12+
EV_DATA_
13+
ENVVAR_DATA_
14+
SGTYPE_
15+
SGTYPE_VAL_
16+
BA_DEF_SGTYPE_
17+
BA_SGTYPE_
18+
SIG_TYPE_REF_
19+
VAL_TABLE_
20+
SIG_GROUP_
21+
SIG_VALTYPE_
22+
SIGTYPE_VALTYPE_
23+
BO_TX_BU_
24+
BA_DEF_REL_
25+
BA_REL_
26+
BA_DEF_DEF_REL_
27+
BU_SG_REL_
28+
BU_EV_REL_
29+
BU_BO_REL_
30+
31+
BS_:
32+
33+
BU_: TestNode
34+
35+
BO_ 1296 TEST_FRAME_1: 2 TestNode
36+
SG_ TEST_SIG_1 : 0|8@1+ (1.0,0) [0|0] "" TestNode
37+
SG_ TEST_SIG_2 : 8|8@1+ (0.1,0) [0|0] "" TestNode

0 commit comments

Comments
 (0)