diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index bfa60b387..ce8af55db 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -27,90 +27,6 @@ cmCacheManager::cmCacheManager() this->CacheMinorVersion = 0; } -static bool ParseEntryWithoutType(const std::string& entry, - std::string& var, - std::string& value) -{ - // input line is: key=value - static cmsys::RegularExpression reg( - "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); - // input line is: "key"=value - static cmsys::RegularExpression regQuoted( - "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); - bool flag = false; - if(regQuoted.find(entry)) - { - var = regQuoted.match(1); - value = regQuoted.match(2); - flag = true; - } - else if (reg.find(entry)) - { - var = reg.match(1); - value = reg.match(2); - flag = true; - } - - // if value is enclosed in single quotes ('foo') then remove them - // it is used to enclose trailing space or tab - if (flag && - value.size() >= 2 && - value[0] == '\'' && - value[value.size() - 1] == '\'') - { - value = value.substr(1, - value.size() - 2); - } - - return flag; -} - -bool cmCacheManager::ParseEntry(const std::string& entry, - std::string& var, - std::string& value, - cmState::CacheEntryType& type) -{ - // input line is: key:type=value - static cmsys::RegularExpression reg( - "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); - // input line is: "key":type=value - static cmsys::RegularExpression regQuoted( - "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); - bool flag = false; - if(regQuoted.find(entry)) - { - var = regQuoted.match(1); - type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str()); - value = regQuoted.match(3); - flag = true; - } - else if (reg.find(entry)) - { - var = reg.match(1); - type = cmState::StringToCacheEntryType(reg.match(2).c_str()); - value = reg.match(3); - flag = true; - } - - // if value is enclosed in single quotes ('foo') then remove them - // it is used to enclose trailing space or tab - if (flag && - value.size() >= 2 && - value[0] == '\'' && - value[value.size() - 1] == '\'') - { - value = value.substr(1, - value.size() - 2); - } - - if (!flag) - { - return ParseEntryWithoutType(entry, var, value); - } - - return flag; -} - void cmCacheManager::CleanCMakeFiles(const std::string& path) { std::string glob = path; @@ -187,7 +103,7 @@ bool cmCacheManager::LoadCache(const std::string& path, } } e.SetProperty("HELPSTRING", helpString.c_str()); - if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type)) + if(cmState::ParseCacheEntry(realbuffer, entryKey, e.Value, e.Type)) { if ( excludes.find(entryKey) == excludes.end() ) { diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 24400663a..6f063ebbc 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -121,12 +121,6 @@ public: int GetSize() { return static_cast(this->Cache.size()); } - ///! Break up a line like VAR:type="value" into var, type and value - static bool ParseEntry(const std::string& entry, - std::string& var, - std::string& value, - cmState::CacheEntryType& type); - ///! Get a value from the cache given a key const char* GetInitializedCacheValue(const std::string& key) const; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 3aad7f5d6..c5bbf42cc 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -1769,3 +1769,87 @@ bool operator!=(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs) { return lhs.Position != rhs.Position; } + +static bool ParseEntryWithoutType(const std::string& entry, + std::string& var, + std::string& value) +{ + // input line is: key=value + static cmsys::RegularExpression reg( + "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); + // input line is: "key"=value + static cmsys::RegularExpression regQuoted( + "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); + bool flag = false; + if(regQuoted.find(entry)) + { + var = regQuoted.match(1); + value = regQuoted.match(2); + flag = true; + } + else if (reg.find(entry)) + { + var = reg.match(1); + value = reg.match(2); + flag = true; + } + + // if value is enclosed in single quotes ('foo') then remove them + // it is used to enclose trailing space or tab + if (flag && + value.size() >= 2 && + value[0] == '\'' && + value[value.size() - 1] == '\'') + { + value = value.substr(1, + value.size() - 2); + } + + return flag; +} + +bool cmState::ParseCacheEntry(const std::string& entry, + std::string& var, + std::string& value, + CacheEntryType& type) +{ + // input line is: key:type=value + static cmsys::RegularExpression reg( + "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); + // input line is: "key":type=value + static cmsys::RegularExpression regQuoted( + "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); + bool flag = false; + if(regQuoted.find(entry)) + { + var = regQuoted.match(1); + type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str()); + value = regQuoted.match(3); + flag = true; + } + else if (reg.find(entry)) + { + var = reg.match(1); + type = cmState::StringToCacheEntryType(reg.match(2).c_str()); + value = reg.match(3); + flag = true; + } + + // if value is enclosed in single quotes ('foo') then remove them + // it is used to enclose trailing space or tab + if (flag && + value.size() >= 2 && + value[0] == '\'' && + value[value.size() - 1] == '\'') + { + value = value.substr(1, + value.size() - 2); + } + + if (!flag) + { + return ParseEntryWithoutType(entry, var, value); + } + + return flag; +} diff --git a/Source/cmState.h b/Source/cmState.h index 4c32831b6..fbc9275de 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -242,6 +242,12 @@ public: void RemoveCacheEntryProperty(std::string const& key, std::string const& propertyName); + ///! Break up a line like VAR:type="value" into var, type and value + static bool ParseCacheEntry(const std::string& entry, + std::string& var, + std::string& value, + CacheEntryType& type); + Snapshot Reset(); // Define a property void DefineProperty(const std::string& name, cmProperty::ScopeType scope, diff --git a/Source/cmake.cxx b/Source/cmake.cxx index b90ac6943..b1c270919 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -216,7 +216,7 @@ bool cmake::SetCacheArgs(const std::vector& args) } std::string var, value; cmState::CacheEntryType type = cmState::UNINITIALIZED; - if(cmCacheManager::ParseEntry(entry, var, value, type)) + if(cmState::ParseCacheEntry(entry, var, value, type)) { // The value is transformed if it is a filepath for example, so // we can't compare whether the value is already in the cache until @@ -1722,7 +1722,7 @@ bool cmake::ParseCacheEntry(const std::string& entry, std::string& value, cmState::CacheEntryType& type) { - return cmCacheManager::ParseEntry(entry, var, value, type); + return cmState::ParseCacheEntry(entry, var, value, type); } int cmake::LoadCache()