summaryrefslogtreecommitdiffstats
path: root/Source/cmPolicies.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-05-03 08:09:29 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-05-04 20:32:17 (GMT)
commita7ff97275159d094f55df481728a682c357bc438 (patch)
tree0527d2faf76790a1fc22136162c84a8a02cfb6f3 /Source/cmPolicies.cxx
parent953d1b00af3059b24c4dadf8c4717cb0d2260e36 (diff)
downloadCMake-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.cxx50
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)