Fix issues parsing some composition strings
The parser was having issues in cases where there was both a space following the colon and a comma following the value.
This commit is contained in:
parent
5fcbfde40e
commit
3f6f580b25
2 changed files with 12 additions and 3 deletions
|
|
@ -141,17 +141,17 @@ compositionMap parseCompString(const std::string& ss,
|
|||
|
||||
double value;
|
||||
try {
|
||||
value = fpValueCheck(ss.substr(valstart, stop-colon-1));
|
||||
value = fpValueCheck(ss.substr(valstart, stop-valstart));
|
||||
} catch (CanteraError& err) {
|
||||
// If we have a key containing a colon, we expect this to fail. In
|
||||
// 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(start, stop-colon-1);
|
||||
std::string testname = ss.substr(start, stop-start);
|
||||
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) {
|
||||
} else if (ss.substr(valstart, stop-valstart).find(':') != npos) {
|
||||
left = colon + 1;
|
||||
stop = 0; // Force another iteration of this loop
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,15 @@ TEST(parseCompString, space_separated)
|
|||
ASSERT_DOUBLE_EQ(1e-4, c["baz"]);
|
||||
}
|
||||
|
||||
TEST(parseCompString, comma_separated)
|
||||
{
|
||||
compositionMap c = parseCompString("foo:1.0, bar: 2, baz:1e-4");
|
||||
ASSERT_EQ((size_t) 3, c.size());
|
||||
ASSERT_DOUBLE_EQ(1.0, c["foo"]);
|
||||
ASSERT_DOUBLE_EQ(2.0, c["bar"]);
|
||||
ASSERT_DOUBLE_EQ(1e-4, c["baz"]);
|
||||
}
|
||||
|
||||
TEST(parseCompString, extra_spaces)
|
||||
{
|
||||
compositionMap c = parseCompString("foo: 1.0 bar: 2 baz : 1e-4");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue