File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -799,8 +799,15 @@ class LIBSCRATCHCPP_EXPORT Value
799799 if (ok)
800800 *ok = true ;
801801
802+ // Set locale to C to avoid conversion issues
803+ std::string oldLocale = std::setlocale (LC_NUMERIC, nullptr );
804+ std::setlocale (LC_NUMERIC, " C" );
805+
802806 double ret = std::stod (*stringPtr);
803807
808+ // Restore old locale
809+ std::setlocale (LC_NUMERIC, oldLocale.c_str ());
810+
804811 if (customStr)
805812 delete stringPtr;
806813
Original file line number Diff line number Diff line change @@ -135,6 +135,24 @@ TEST(ValueTest, StdStringConstructor)
135135 ASSERT_FALSE (v.isString ());
136136 }
137137
138+ {
139+ std::string oldLocale = std::setlocale (LC_NUMERIC, nullptr );
140+ std::setlocale (LC_NUMERIC, " sk_SK.UTF-8" );
141+
142+ Value v (std::string (" 532.15" ));
143+
144+ std::setlocale (LC_NUMERIC, oldLocale.c_str ());
145+
146+ ASSERT_EQ (v.toString (), " 532.15" );
147+ ASSERT_EQ (v.type (), Value::Type::Double);
148+ ASSERT_FALSE (v.isInfinity ());
149+ ASSERT_FALSE (v.isNegativeInfinity ());
150+ ASSERT_FALSE (v.isNaN ());
151+ ASSERT_TRUE (v.isNumber ());
152+ ASSERT_FALSE (v.isBool ());
153+ ASSERT_FALSE (v.isString ());
154+ }
155+
138156 {
139157 Value v (std::string (" 1 2 3" ));
140158 ASSERT_EQ (v.toString (), " 1 2 3" );
You can’t perform that action at this time.
0 commit comments