Fixed various bugs in kart characteristics: a negative value for

a float now works, also longer computations like 1+2*3 (see unit
testing).
This commit is contained in:
hiker 2016-06-30 09:20:24 +10:00
parent 9efb4da2ec
commit 48dbc6c80a

View File

@ -212,8 +212,9 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
std::size_t pos2; std::size_t pos2;
while ((pos2 = processor.find_first_of(operators, pos)) != std::string::npos) while ((pos2 = processor.find_first_of(operators, pos)) != std::string::npos)
{ {
parts.push_back(processor.substr(pos, pos2)); std::string s = processor.substr(pos, pos2);
operations.push_back(processor.substr(pos2, pos2 + 1)); parts.push_back(processor.substr(pos, pos2-pos));
operations.push_back(processor.substr(pos2, 1));
pos = pos2 + 1; pos = pos2 + 1;
} }
parts.push_back(processor.substr(pos)); parts.push_back(processor.substr(pos));
@ -224,15 +225,15 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
// If nothing preceeds the first operator, insert x // If nothing preceeds the first operator, insert x
if (parts[index].empty()) if (parts[index].empty())
{ {
if (!*is_set) // - is a special case: We don't take e.g. "-5" as relative, it
// describes a negative number. So
if (!*is_set && operations[index] == "-")
*value = 0;
else if (!*is_set)
{ {
Log::error("XmlCharacteristic::processFloat", "x is unknown"); Log::error("XmlCharacteristic::processFloat", "x is unknown");
return; return;
} }
// - is a special case: We don't take e.g. "-5" as relative, it
// describes a negative number
else if (operations[index] == "-")
*value = 0;
else else
*value = x; *value = x;
} }