From 47c4ee974a2c4af46922c3c1e3417f7d77603d1f Mon Sep 17 00:00:00 2001 From: Philipp Hasper Date: Mon, 11 Apr 2016 09:55:33 +0200 Subject: [PATCH] operator<< handles keys starting with underscore --- modules/core/src/persistence.cpp | 2 +- modules/core/test/test_io.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 9c7b0f2..1b1e956 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -5217,7 +5217,7 @@ FileStorage& operator << (FileStorage& fs, const String& str) } else if( fs.state == NAME_EXPECTED + INSIDE_MAP ) { - if( !cv_isalpha(*_str) ) + if (!cv_isalpha(*_str) && *_str != '_') CV_Error_( CV_StsError, ("Incorrect element name %s", _str) ); fs.elname = str; fs.state = VALUE_EXPECTED + INSIDE_MAP; diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 0c401f8..b53c43c 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -566,3 +566,14 @@ TEST(Core_InputOutput, FileStorage) sprintf(arr, "sprintf is hell %d", 666); EXPECT_NO_THROW(f << arr); } + +TEST(Core_InputOutput, FileStorageKey) +{ + cv::FileStorage f("dummy.yml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY); + + EXPECT_NO_THROW(f << "key1" << "value1"); + EXPECT_NO_THROW(f << "_key2" << "value2"); + EXPECT_NO_THROW(f << "key_3" << "value3"); + const std::string expected = "%YAML:1.0\nkey1: value1\n_key2: value2\nkey_3: value3\n"; + ASSERT_STREQ(f.releaseAndGetString().c_str(), expected.c_str()); +} -- 2.7.4