make the parser case-insensitive

i.e., make keywords ALL_UPPERCASE before using them because Eclipse
seems to be case-insensitive (although this is one of its undocumented
features...)
This commit is contained in:
Andreas Lauser 2014-11-07 10:38:00 +01:00
parent fff0c9cdf0
commit ead7e0a8c9
4 changed files with 18 additions and 8 deletions

View File

@ -206,7 +206,7 @@ namespace Opm {
if (name.length() > ParserConst::maxKeywordLength)
return false;
if (!isupper(name[0]))
if (!isalpha(name[0]))
return false;
return true;
@ -242,13 +242,17 @@ namespace Opm {
}
bool ParserKeyword::validDeckName(const std::string& name) {
if (!validNameStart(name))
// make the keyword string ALL_UPPERCASE because Eclipse seems
// to be case-insensitive (although this is one of its
// undocumented features...)
std::string upperCaseName = boost::to_upper_copy(name);
if (!validNameStart(upperCaseName))
return false;
for (size_t i = 1; i < name.length(); i++) {
char c = name[i];
if (!isupper(c) &&
!isdigit(c) &&
for (size_t i = 1; i < upperCaseName.length(); i++) {
char c = upperCaseName[i];
if (!isalnum(c) &&
c != '-' &&
c != '_' &&
c != '+')

View File

@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) {
BOOST_AUTO_TEST_CASE(ParserKeyword_validDeckName) {
BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("SUMMARY"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("MixeCase"));
BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("MixeCase"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("NAMETOOLONG"));
BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("STRING88"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("88STRING"));

View File

@ -131,6 +131,12 @@ namespace Opm {
// white space is for dicks!
result = boost::trim_right_copy_if(result.substr(0, 8), boost::is_any_of(" \t"));
// make the keyword string ALL_UPPERCASE because Eclipse seems
// to be case-insensitive (although this is one of its
// undocumented features...)
boost::to_upper(result);
if (isValidKeyword(result))
return true;
else

View File

@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialWhitespaceInKeywordThrows) {
}
BOOST_AUTO_TEST_CASE(constructor_mixedCaseName_throws) {
BOOST_CHECK_THROW(RawKeyword("Test", Raw::SLASH_TERMINATED , "FILE" , 10U), std::invalid_argument);
BOOST_CHECK_NO_THROW(RawKeyword("Test", Raw::SLASH_TERMINATED , "FILE" , 10U));
}
BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialTabInKeywordThrows) {