[Base] Fix parsing composition strings when last name contains a colon

If the last species name in a composition string contained a colon, it would not
be parsed correctly.
This commit is contained in:
Ray Speth 2016-11-26 23:59:23 -05:00
parent aa4d07f543
commit 0787e4194e
2 changed files with 9 additions and 1 deletions

View file

@ -147,12 +147,13 @@ compositionMap parseCompString(const std::string& ss,
// this case, take the current substring as part of the key and look
// to the right of the next colon for the corresponding value.
// Otherwise, this is an invalid composition string.
std::string testname = ss.substr(valstart, stop-colon-1);
std::string testname = ss.substr(start, stop-colon-1);
if (testname.find_first_of(" \n\t") != npos) {
// Space, tab, and newline are never allowed in names
throw;
} else if (ss.substr(valstart, stop-colon-1).find(':') != npos) {
left = colon + 1;
stop = 0; // Force another iteration of this loop
continue;
} else {
throw;

View file

@ -33,6 +33,13 @@ TEST(parseCompString, name_with_colon)
ASSERT_DOUBLE_EQ(1e-4, c["baz"]);
}
TEST(parseCompString, name_with_final_colon)
{
compositionMap c = parseCompString("co:lons::1.0");
ASSERT_EQ((size_t) 1, c.size());
ASSERT_DOUBLE_EQ(1.0, c["co:lons:"]);
}
TEST(parseCompString, default_values)
{
std::vector<std::string> x = { "foo", "bar", "baz" };