diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-05-03 08:09:29 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-05-04 20:32:17 (GMT) |
commit | a7ff97275159d094f55df481728a682c357bc438 (patch) | |
tree | 0527d2faf76790a1fc22136162c84a8a02cfb6f3 /Source/cmPolicies.cxx | |
parent | 953d1b00af3059b24c4dadf8c4717cb0d2260e36 (diff) | |
download | CMake-a7ff97275159d094f55df481728a682c357bc438.zip CMake-a7ff97275159d094f55df481728a682c357bc438.tar.gz CMake-a7ff97275159d094f55df481728a682c357bc438.tar.bz2 |
cmPolicies: Parse string for id conversion.
Remove now-unused PolicyStringMap.
Diffstat (limited to 'Source/cmPolicies.cxx')
-rw-r--r-- | Source/cmPolicies.cxx | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 3f9c6f0..6a15965 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -9,6 +9,42 @@ #include <queue> #include <assert.h> +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<std::string,cmPolicies::PolicyID>::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) |