Added static method ParserKeyword::validName()
This commit is contained in:
parent
9848ef4d25
commit
4202ad027d
@ -90,14 +90,25 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
bool ParserKeyword::validName(const std::string& name) {
|
||||
if (name.length() > ParserConst::maxKeywordLength)
|
||||
return false;
|
||||
|
||||
if (isdigit(name[0]))
|
||||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < name.length(); i++)
|
||||
if (islower(name[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::commonInit(const std::string& name) {
|
||||
if (name.length() > ParserConst::maxKeywordLength)
|
||||
throw std::invalid_argument("Given keyword name is too long - max 8 characters.");
|
||||
|
||||
for (unsigned int i = 0; i < name.length(); i++)
|
||||
if (islower(name[i]))
|
||||
throw std::invalid_argument("Keyword must be all upper case - mixed case not allowed:" + name);
|
||||
|
||||
if (!validName(name))
|
||||
throw std::invalid_argument("Invalid name: " + name + "keyword must be all upper case, max 8 characters. Starting with character.");
|
||||
|
||||
m_name = name;
|
||||
m_record = ParserRecordPtr(new ParserRecord);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ namespace Opm {
|
||||
ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem);
|
||||
ParserKeyword(const Json::JsonObject& jsonConfig);
|
||||
|
||||
static bool validName(const std::string& name);
|
||||
|
||||
ParserRecordPtr getRecord();
|
||||
const std::string& getName() const;
|
||||
|
@ -67,6 +67,14 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) {
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserKeyword_validName) {
|
||||
BOOST_CHECK_EQUAL( true , ParserKeyword::validName("SUMMARY"));
|
||||
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("MixeCase"));
|
||||
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("NAMETOOLONG"));
|
||||
BOOST_CHECK_EQUAL( true , ParserKeyword::validName("STRING88"));
|
||||
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("88STRING"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user