File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,26 @@ extern "C"
320320 }
321321 }
322322
323+ // If there's a trailing dot, copy the string and append zero next to it (e. g. '1.' -> '1.0')
324+ if (end[-1 ] == ' .' ) {
325+ if (copy) {
326+ char *tmpCopy = new char [end - begin + 2 ];
327+ memcpy (tmpCopy, begin, end - begin);
328+ delete[] copy;
329+ copy = tmpCopy;
330+ end = copy + (end - begin) + 1 ;
331+ begin = copy;
332+ } else {
333+ copy = new char [end - begin + 2 ];
334+ memcpy (copy, begin, end - begin);
335+ end = copy + (end - begin) + 1 ;
336+ begin = copy;
337+ }
338+
339+ copy[end - begin - 1 ] = ' 0' ;
340+ copy[end - begin] = ' \0 ' ;
341+ }
342+
323343 // Trim leading zeros
324344 bool trimmed = false ;
325345
Original file line number Diff line number Diff line change @@ -1297,6 +1297,13 @@ TEST(ValueTest, ToDouble)
12971297 v = " -.15" ;
12981298 ASSERT_EQ (v.toDouble (), -0.15 );
12991299
1300+ v = " 1." ;
1301+ ASSERT_EQ (v.toDouble (), 1 );
1302+ v = " +1." ;
1303+ ASSERT_EQ (v.toDouble (), 1 );
1304+ v = " -1." ;
1305+ ASSERT_EQ (v.toDouble (), -1 );
1306+
13001307 v = " 0+5" ;
13011308 ASSERT_EQ (v.toDouble (), 0 );
13021309 v = " 0-5" ;
You can’t perform that action at this time.
0 commit comments