From f07e2d6be48d5523ee839e5f3a5f7ac41374a7fd Mon Sep 17 00:00:00 2001 From: Marek Otahal Date: Thu, 18 Jan 2018 20:11:40 +0100 Subject: [PATCH] YAML: remove old workaround for 1-letter strings apparently, yaml-cpp had a bug and did not handle 1 letter strings "1" Now it seems to work ok. Add test --- src/nupic/engine/YAMLUtils.cpp | 19 +------------------ src/test/unit/engine/YAMLUtilsTest.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/nupic/engine/YAMLUtils.cpp b/src/nupic/engine/YAMLUtils.cpp index e71842238c..5b2e1aa56d 100644 --- a/src/nupic/engine/YAMLUtils.cpp +++ b/src/nupic/engine/YAMLUtils.cpp @@ -177,18 +177,8 @@ static Value toValue(const YAML::Node& node, NTA_BasicType dataType) */ Value toValue(const std::string& yamlstring, NTA_BasicType dataType) { - // IMemStream s(yamlstring, ::strlen(yamlstring)); - - // yaml-cpp bug: append a space if it is only one character - // This is very inefficient, but should be ok since it is - // just used at construction time for short strings - //FIXME try remove now - std::string paddedstring(yamlstring); - if (paddedstring.size() < 2) - paddedstring = paddedstring + " "; - // TODO -- return value? exceptions? - const YAML::Node doc = YAML::Load(paddedstring); + const YAML::Node doc = YAML::Load(yamlstring); return toValue(doc, dataType); } @@ -203,17 +193,10 @@ ValueMap toValueMap(const char* yamlstring, ValueMap vm; - // yaml-cpp bug: append a space if it is only one character - // This is very inefficient, but should be ok since it is - // just used at construction time for short strings std::string paddedstring(yamlstring); // TODO: strip white space to determine if empty bool empty = (paddedstring.size() == 0); -//FIXME try removing this - if (paddedstring.size() < 2) - paddedstring = paddedstring + " "; - // TODO: utf-8 compatible? const YAML::Node doc = YAML::Load(paddedstring); if(!empty) { diff --git a/src/test/unit/engine/YAMLUtilsTest.cpp b/src/test/unit/engine/YAMLUtilsTest.cpp index 2e1caffe90..be67b40361 100644 --- a/src/test/unit/engine/YAMLUtilsTest.cpp +++ b/src/test/unit/engine/YAMLUtilsTest.cpp @@ -45,6 +45,12 @@ TEST(YAMLUtilsTest, toValueTestInt) ASSERT_EQ(10, i); } +TEST(YAMLUtilsTest, handle1LetterInputString) +{ + const char* s1 = "1"; + EXPECT_NO_THROW(YAMLUtils::toValue(s1, NTA_BasicType_Int32)); +} + TEST(YAMLUtilsTest, toValueTestReal32) { const char* s1 = "10.1";