Commit e2eecae2 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmState: Move ParseCacheEntry from cmCacheManager.

parent b5212c68
......@@ -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() )
{
......
......@@ -121,12 +121,6 @@ public:
int GetSize() {
return static_cast<int>(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;
......
......@@ -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;
}
......@@ -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,
......
......@@ -216,7 +216,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& 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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment