Allow deck_names in ParserKeyword to be interpreted as regexp

This commit is contained in:
Joakim Hove 2020-11-13 08:19:43 +01:00
parent 893fcbb9fb
commit cfbafc236a
3 changed files with 17 additions and 3 deletions

View File

@ -707,9 +707,18 @@ void set_dimensions( ParserItem& item,
else if( m_deckNames.count( std::string(name) ) )
return true;
else if (hasMatchRegex())
return std::regex_match( name.begin(), name.end(), m_matchRegex);
else if (hasMatchRegex()) {
bool match = std::regex_match( name.begin(), name.end(), m_matchRegex);
if (match)
return true;
}
// Last desperate attempt - go through the deckNames list and
// interpret the elements as a regular expression.
for (const auto& deck_name : this->m_deckNames) {
if (std::regex_match(name.begin(), name.end(), std::regex(deck_name)))
return true;
}
return false;
}

View File

@ -5,6 +5,7 @@
],
"comment": "Tracer keywords where the 2nd letter is a 'T' should be compounded with the tracer name",
"deck_names": [
"RRPV_[0-9A-Z][0-9A-Z][0-9A-Z]",
"ROSAT",
"ROIP",
"ROIPL",

View File

@ -1178,11 +1178,15 @@ RPR__REG
ROPT_REG
/
RRPV_REG
/
)";
const auto& summary_config = createSummary(deck_string);
BOOST_CHECK_EQUAL(summary_config.size(), 6U);
BOOST_CHECK_EQUAL(summary_config.size(), 9U);
BOOST_CHECK(summary_config.hasKeyword("RPR__REG"));
BOOST_CHECK(summary_config.hasKeyword("ROPT_REG"));
BOOST_CHECK(summary_config.hasKeyword("RRPV_REG"));
BOOST_CHECK(!summary_config.hasKeyword("RPR"));
BOOST_CHECK(!summary_config.match("BPR*"));
BOOST_CHECK(summary_config.match("RPR*"));