Merge pull request #6892 from ioxp:fsSpace

This commit is contained in:
Alexander Alekhin 2016-07-13 11:46:50 +00:00
commit 53f4eaa7a7
2 changed files with 17 additions and 1 deletions

View File

@ -1852,7 +1852,7 @@ icvYMLWriteString( CvFileStorage* fs, const char* key,
if( quote || len == 0 || str[0] != str[len-1] || (str[0] != '\"' && str[0] != '\'') )
{
int need_quote = quote || len == 0;
int need_quote = quote || len == 0 || str[0] == ' ';
data = buf;
*data++ = '\"';
for( i = 0; i < len; i++ )

View File

@ -578,6 +578,22 @@ TEST(Core_InputOutput, FileStorageKey)
ASSERT_STREQ(f.releaseAndGetString().c_str(), expected.c_str());
}
TEST(Core_InputOutput, FileStorageSpaces)
{
cv::FileStorage f("dummy.yml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY);
const int valueCount = 5;
std::string values[5] = { "", " ", " ", " a", " some string" };
for (size_t i = 0; i < valueCount; i++) {
EXPECT_NO_THROW(f << cv::format("key%d", i) << values[i]);
}
cv::FileStorage f2(f.releaseAndGetString(), cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::string valuesRead[valueCount];
for (size_t i = 0; i < valueCount; i++) {
EXPECT_NO_THROW(f2[cv::format("key%d", i)] >> valuesRead[i]);
ASSERT_STREQ(values[i].c_str(), valuesRead[i].c_str());
}
}
TEST(Core_InputOutput, filestorage_yml_compatibility)
{
// TODO: