From a7ff97275159d094f55df481728a682c357bc438 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 3 May 2015 10:09:29 +0200 Subject: [PATCH] cmPolicies: Parse string for id conversion. Remove now-unused PolicyStringMap. --- Source/cmPolicies.cxx | 50 ++++++++++++++++++++++++++++++++----------- Source/cmPolicies.h | 1 - 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 3f9c6f0ca0..6a159655bc 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -9,6 +9,42 @@ #include #include +static bool stringToId(const char* input, cmPolicies::PolicyID& pid) +{ + assert(input); + if (strlen(input) != 7) + { + return false; + } + if (!cmHasLiteralPrefix(input, "CMP")) + { + return false; + } + if (cmHasLiteralSuffix(input, "0000")) + { + pid = cmPolicies::CMP0000; + return true; + } + for (int i = 3; i < 7; ++i) + { + if (!isdigit(*(input + i))) + { + return false; + } + } + long id; + if (!cmSystemTools::StringToLong(input + 3, &id)) + { + return false; + } + if (id >= cmPolicies::CMPCOUNT) + { + return false; + } + pid = cmPolicies::PolicyID(id); + return true; +} + class cmPolicy { public: @@ -405,7 +441,6 @@ void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD, minorVersionIntroduced, patchVersionIntroduced, status); - this->PolicyStringMap[idString] = iD; } //---------------------------------------------------------------------------- @@ -542,18 +577,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid) { - if (!id || strlen(id) < 1) - { - return false; - } - std::map::iterator pos = - this->PolicyStringMap.find(id); - if (pos == this->PolicyStringMap.end()) - { - return false; - } - pid = pos->second; - return true; + return stringToId(id, pid); } std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid) diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 9de0298d30..a3654f1d37 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -159,7 +159,6 @@ public: private: // might have to make these internal for VS6 not sure yet std::map Policies; - std::map PolicyStringMap; void DiagnoseAncientPolicies(std::vector const& ancient, unsigned int majorVer, unsigned int minorVer,