Changed direct calls to strtod to use StringToNumber

StringToNumber will correctly use locale-insensitive functions
when available.

Change-Id: I6bde11039a541634186f8f791012af2eb0d86b8d
This commit is contained in:
Wouter van Oortmerssen
2020-01-09 11:47:02 -08:00
parent 718351831d
commit 55686100aa
3 changed files with 25 additions and 8 deletions

View File

@@ -56,7 +56,13 @@ double GetAnyValueF(reflection::BaseType type, const uint8_t *data) {
case reflection::String: {
auto s =
reinterpret_cast<const String *>(ReadScalar<uoffset_t>(data) + data);
return s ? strtod(s->c_str(), nullptr) : 0.0;
if (s) {
double d;
StringToNumber(s->c_str(), &d);
return d;
} else {
return 0.0;
}
}
default: return static_cast<double>(GetAnyValueI(type, data));
}
@@ -149,9 +155,12 @@ void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val) {
void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val) {
switch (type) {
case reflection::Float:
case reflection::Double:
SetAnyValueF(type, data, strtod(val, nullptr));
case reflection::Double: {
double d;
StringToNumber(val, &d);
SetAnyValueF(type, data, d);
break;
}
// TODO: support strings.
default: SetAnyValueI(type, data, StringToInt(val)); break;
}