@@ -60,13 +60,28 @@ using namespace OpenSim;
60
60
using namespace std ;
61
61
62
62
// STATICS
63
- bool IO::_Scientific = false ;
64
- bool IO::_GFormatForDoubleOutput = false ;
65
- int IO::_Pad = 8 ;
66
- int IO::_Precision = 8 ;
67
- char IO::_DoubleFormat[] = " %16.8lf" ;
68
- bool IO::_PrintOfflineDocuments = true ;
69
- const std::locale _locale = std::locale::classic();
63
+ namespace
64
+ {
65
+ constexpr int IO_DBLFMTLEN = 256 ;
66
+
67
+ /* * Specifies whether number output is in scientific or float format. */
68
+ bool _Scientific = false ;
69
+
70
+ /* * Specifies whether number output is in %g format or not. */
71
+ bool _GFormatForDoubleOutput = false ;
72
+
73
+ /* * Specifies number of digits of padding in number output. */
74
+ int _Pad = 8 ;
75
+
76
+ /* * Specifies the precision of number output. */
77
+ int _Precision = 8 ;
78
+
79
+ /* * The output format string. */
80
+ char _DoubleFormat[IO_DBLFMTLEN] = " %16.8lf" ;
81
+
82
+ /* * Whether offline documents should also be printed when Object::print is called. */
83
+ bool _PrintOfflineDocuments = true ;
84
+ }
70
85
71
86
72
87
// =============================================================================
@@ -482,10 +497,16 @@ double IO::
482
497
stod (const std::string& __str, std::size_t * __idx)
483
498
{
484
499
std::istringstream iss (__str);
485
- iss.imbue (_locale);
500
+
501
+ // Always parse numbers with "C" locale, which uses a period character
502
+ // for the decimal place. Otherwise, Finns, Dutch, and other locales
503
+ // that use comma characters as a decimal place will encounter parsing
504
+ // issues (#3943, #3924).
505
+ iss.imbue (std::locale::classic ());
506
+
486
507
double result;
487
508
iss >> result;
488
- if (iss.fail ()){
509
+ if (iss.fail ()) {
489
510
result = std::numeric_limits<double >::quiet_NaN ();
490
511
log_warn (" Encountered non-numeric string value: {} ; parsed value:{}" ,__str, result);
491
512
}
0 commit comments