提交 c3a8db6d 编写于 作者: M Matt Bennett 提交者: Alexander Alekhin

Merge pull request #7952 from mattmyne:JSONWriteFixTrailingDecimalPoint

Append zero to trailing decimal place for FileStorage JSON write of a float or double value (#7952)

* Fix for FileStorage JSON write of a float or double value that has no fractional part; appends a zero character after the trailing decimal place to meet JSON standard.

* strlen return to size_t type rather than unnecessary cast to int
上级 23e53a32
......@@ -4025,7 +4025,14 @@ static void
icvJSONWriteReal( CvFileStorage* fs, const char* key, double value )
{
char buf[128];
icvJSONWrite( fs, key, icvDoubleToString( buf, value ));
size_t len = strlen( icvDoubleToString( buf, value ) );
if( len > 0 && buf[len-1] == '.' )
{
// append zero if string ends with decimal place to match JSON standard
buf[len] = '0';
buf[len+1] = '\0';
}
icvJSONWrite( fs, key, buf );
}
......@@ -4829,6 +4836,17 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
}
else
{
if( elem_type == CV_32F || elem_type == CV_64F )
{
size_t buf_len = strlen(ptr);
if( buf_len > 0 && ptr[buf_len-1] == '.' )
{
// append zero if CV_32F or CV_64F string ends with decimal place to match JSON standard
// ptr will point to buf, so can write to buf given ptr is const
buf[buf_len] = '0';
buf[buf_len+1] = '\0';
}
}
icvJSONWrite( fs, 0, ptr );
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册