Skip to content

Commit

Permalink
Don't use C++ that breaks VS.
Browse files Browse the repository at this point in the history
Add test for sanitize.
  • Loading branch information
abellgithub committed Sep 25, 2014
1 parent 95a9ed5 commit 50d6fda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Metadata.cpp
Expand Up @@ -44,15 +44,20 @@

std::string sanitize(const std::string& name)
{
std::vector<std::string> to_replace = {";", ":", " ", "'", "\""};
auto ischar = [](char c)
{
return c == ';' || c == ':' || c == ' ' || c == '\'' || c == '\"';
};

std::string v(name);
for (auto c: to_replace)
std::string v;
for (size_t i = 0; i < name.size(); ++i)
{
v = boost::algorithm::replace_all_copy(v, c, "_");
if (ischar(name[i]))
v += '_';
else
v += name[i];
}
return v;

}

namespace pdal
Expand Down
7 changes: 7 additions & 0 deletions test/unit/MetadataTest.cpp
Expand Up @@ -262,6 +262,13 @@ BOOST_AUTO_TEST_CASE(find_child_string)
BOOST_CHECK_EQUAL(n.value(), "220");
}

BOOST_AUTO_TEST_CASE(sanitize)
{
MetadataNode top(" Test;semicolon:colon space'apostrophe\"quote:");
BOOST_CHECK_EQUAL(top.name(),
"_Test_semicolon_colon_space_apostrophe_quote_");
}

BOOST_AUTO_TEST_CASE(toJSON)
{
/**
Expand Down

0 comments on commit 50d6fda

Please sign in to comment.