Skip to content

Commit

Permalink
YAML: remove old workaround for 1-letter strings
Browse files Browse the repository at this point in the history
apparently, yaml-cpp had a bug and did not handle 1 letter strings "1"
Now it seems to work ok.
Add test
  • Loading branch information
breznak committed Jan 25, 2018
1 parent f6ac7b8 commit f07e2d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
19 changes: 1 addition & 18 deletions src/nupic/engine/YAMLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/unit/engine/YAMLUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit f07e2d6

Please sign in to comment.