mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user