From 4bf1adc59308b5128e550fca3aa123b90ca3ca13 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 2 Dec 2013 11:10:53 +0100 Subject: [PATCH 1/2] Changed unsigned int -> size_t. --- opm/parser/eclipse/Parser/ParserKeyword.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index a9f42ec1a..5ce9ef0ab 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -154,7 +154,7 @@ namespace Opm { if (!isupper(name[0])) return false; - for (unsigned int i = 1; i < name.length(); i++) { + for (size_t i = 1; i < name.length(); i++) { char c = name[i]; if (!(isupper(c) || isdigit(c))) { if ((i == (name.length() - 1)) && (c == '*')) @@ -174,7 +174,7 @@ namespace Opm { if (!isupper(name[0])) return false; - for (unsigned int i = 1; i < name.length(); i++) { + for (size_t i = 1; i < name.length(); i++) { char c = name[i]; if (!(isupper(c) || isdigit(c))) return wildCardName(name); From 6b5367854a07608df8624a7c3d9c4ebb558a070b Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 2 Dec 2013 11:19:22 +0100 Subject: [PATCH 2/2] Factored out some common code from validName() and wildCardName(). --- opm/parser/eclipse/Parser/ParserKeyword.cpp | 16 +++++++++++----- opm/parser/eclipse/Parser/ParserKeyword.hpp | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index 5ce9ef0ab..4a51ac65e 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -147,13 +147,21 @@ namespace Opm { } - bool ParserKeyword::wildCardName(const std::string& name) { + bool ParserKeyword::validNameStart(const std::string& name) { if (name.length() > ParserConst::maxKeywordLength) return false; if (!isupper(name[0])) return false; + return true; + } + + + bool ParserKeyword::wildCardName(const std::string& name) { + if (!validNameStart(name)) + return false; + for (size_t i = 1; i < name.length(); i++) { char c = name[i]; if (!(isupper(c) || isdigit(c))) { @@ -168,10 +176,7 @@ namespace Opm { bool ParserKeyword::validName(const std::string& name) { - if (name.length() > ParserConst::maxKeywordLength) - return false; - - if (!isupper(name[0])) + if (!validNameStart(name)) return false; for (size_t i = 1; i < name.length(); i++) { @@ -182,6 +187,7 @@ namespace Opm { return true; } + void ParserKeyword::addItem(ParserItemConstPtr item) { if (m_isDataKeyword) throw std::invalid_argument("Keyword:" + getName() + " is already configured as data keyword - can not add more items."); diff --git a/opm/parser/eclipse/Parser/ParserKeyword.hpp b/opm/parser/eclipse/Parser/ParserKeyword.hpp index 966a932bb..c0f4f07f8 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.hpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.hpp @@ -73,6 +73,7 @@ namespace Opm { bool m_isTableCollection; ParserKeywordActionEnum m_action; + static bool validNameStart(const std::string& name); void initData( const Json::JsonObject& jsonConfig ); void initSize( const Json::JsonObject& jsonConfig ); void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);