skip everything after and including dot when parsing int values
This commit is contained in:
@@ -1115,7 +1115,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
|
|||||||
return RESULT_ERR_EOF; // input too short
|
return RESULT_ERR_EOF; // input too short
|
||||||
else {
|
else {
|
||||||
char* strEnd = NULL;
|
char* strEnd = NULL;
|
||||||
if (m_divisor >= 0 && m_divisor <= 1) {
|
if (m_divisor == 1) {
|
||||||
if ((m_dataType.flags & SIG) != 0) {
|
if ((m_dataType.flags & SIG) != 0) {
|
||||||
long int signedValue = strtol(str, &strEnd, 10);
|
long int signedValue = strtol(str, &strEnd, 10);
|
||||||
if (signedValue < 0 && m_bitCount != 32)
|
if (signedValue < 0 && m_bitCount != 32)
|
||||||
@@ -1125,7 +1125,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = (unsigned int)strtoul(str, &strEnd, 10);
|
value = (unsigned int)strtoul(str, &strEnd, 10);
|
||||||
if (strEnd == NULL || strEnd == str || *strEnd != 0)
|
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
|
||||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||||
} else {
|
} else {
|
||||||
char* strEnd = NULL;
|
char* strEnd = NULL;
|
||||||
@@ -1261,7 +1261,7 @@ result_t ValueListDataField::writeSymbols(istringstream& input,
|
|||||||
char* strEnd = NULL; // fall back to raw value in input
|
char* strEnd = NULL; // fall back to raw value in input
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
value = (unsigned int)strtoul(str, &strEnd, 10);
|
value = (unsigned int)strtoul(str, &strEnd, 10);
|
||||||
if (strEnd == NULL || strEnd == str || *strEnd != 0)
|
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
|
||||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||||
if (m_values.find(value) != m_values.end())
|
if (m_values.find(value) != m_values.end())
|
||||||
return writeRawValue(value, baseOffset, output);
|
return writeRawValue(value, baseOffset, output);
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ int main()
|
|||||||
{"x,s,uch", "0", "1025ffff00", "0100", ""},
|
{"x,s,uch", "0", "1025ffff00", "0100", ""},
|
||||||
{"x,s,uch,,,,y,m,uch", "3;2","1025ffff0103", "0102", ""},
|
{"x,s,uch,,,,y,m,uch", "3;2","1025ffff0103", "0102", ""},
|
||||||
{"x,,uch", "38", "10feffff0126", "00", ""},
|
{"x,,uch", "38", "10feffff0126", "00", ""},
|
||||||
|
{"x,,uch", "38.5", "10feffff0126", "00", "R"},
|
||||||
{"x,,uch", "0", "10feffff0100", "00", ""},
|
{"x,,uch", "0", "10feffff0100", "00", ""},
|
||||||
{"x,,uch", "254", "10feffff01fe", "00", ""},
|
{"x,,uch", "254", "10feffff01fe", "00", ""},
|
||||||
{"x,,uch", "-", "10feffff01ff", "00", ""},
|
{"x,,uch", "-", "10feffff01ff", "00", ""},
|
||||||
@@ -235,6 +236,7 @@ int main()
|
|||||||
{"x,,bi3:2,1=on","on", "10feffff0108", "00", ""},
|
{"x,,bi3:2,1=on","on", "10feffff0108", "00", ""},
|
||||||
{"x,,bi3:2,1=on","-", "10feffff0100", "00", ""},
|
{"x,,bi3:2,1=on","-", "10feffff0100", "00", ""},
|
||||||
{"x,,bi3:2,0=off;1=on;2=auto;3=eco","auto", "10feffff0110", "00", ""},
|
{"x,,bi3:2,0=off;1=on;2=auto;3=eco","auto", "10feffff0110", "00", ""},
|
||||||
|
{"x,,bi3:2,0=off;1=on;2=auto;3=eco","2.5", "10feffff0110", "00", "R"},
|
||||||
{"x,,bi3:2,0=off;1=on","on", "10feffff0108", "00", ""},
|
{"x,,bi3:2,0=off;1=on","on", "10feffff0108", "00", ""},
|
||||||
{"x,,bi3:2,0=off;1=on","off","10feffff0100", "00", ""},
|
{"x,,bi3:2,0=off;1=on","off","10feffff0100", "00", ""},
|
||||||
{"x,,bi3:2,0=off;1=on","1", "10feffff0108", "00", "n"},
|
{"x,,bi3:2,0=off;1=on","1", "10feffff0108", "00", "n"},
|
||||||
|
|||||||
Reference in New Issue
Block a user