summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorVitaly Stakhovsky <vvs31415@gitlab.org>2020-01-01 13:00:00 (GMT)
committerVitaly Stakhovsky <vvs31415@gitlab.org>2020-01-02 12:56:34 (GMT)
commit232d5bc3339b81170bba940ebad9513a19ceaffb (patch)
tree3fe61328d20eb97d1bc80d674a5602385abe7848 /Source
parent47a907413bb8aa2394a3003c90775b402b53d35a (diff)
downloadCMake-232d5bc3339b81170bba940ebad9513a19ceaffb.zip
CMake-232d5bc3339b81170bba940ebad9513a19ceaffb.tar.gz
CMake-232d5bc3339b81170bba940ebad9513a19ceaffb.tar.bz2
cmState: more members will use std::string
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCacheManager.cxx2
-rw-r--r--Source/cmSetCommand.cxx2
-rw-r--r--Source/cmState.cxx35
-rw-r--r--Source/cmState.h8
4 files changed, 25 insertions, 22 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index d627465..e3536d5 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -617,7 +617,7 @@ const char* cmCacheManager::CacheEntry::GetProperty(
const std::string& prop) const
{
if (prop == "TYPE") {
- return cmState::CacheEntryTypeToString(this->Type);
+ return cmState::CacheEntryTypeToString(this->Type).c_str();
}
if (prop == "VALUE") {
return this->Value.c_str();
diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx
index 8c3a4cb..5e2a146 100644
--- a/Source/cmSetCommand.cxx
+++ b/Source/cmSetCommand.cxx
@@ -121,7 +121,7 @@ bool cmSetCommand(std::vector<std::string> const& args,
if (cache) {
std::string::size_type cacheStart = args.size() - 3 - (force ? 1 : 0);
- if (!cmState::StringToCacheEntryType(args[cacheStart + 1].c_str(), type)) {
+ if (!cmState::StringToCacheEntryType(args[cacheStart + 1], type)) {
std::string m = "implicitly converting '" + args[cacheStart + 1] +
"' to 'STRING' type.";
status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, m);
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 72f663d..9d83a72 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -3,9 +3,9 @@
#include "cmState.h"
#include <algorithm>
+#include <array>
#include <cassert>
#include <cstdlib>
-#include <cstring>
#include <utility>
#include <cm/memory>
@@ -60,43 +60,44 @@ const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType)
return nullptr;
}
-const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH",
- "STRING", "INTERNAL", "STATIC",
- "UNINITIALIZED", nullptr };
+static const std::array<std::string, 7> cmCacheEntryTypes = {
+ { "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC",
+ "UNINITIALIZED" }
+};
-const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type)
+const std::string& cmState::CacheEntryTypeToString(
+ cmStateEnums::CacheEntryType type)
{
- if (type > 6) {
- return cmCacheEntryTypes[6];
+ if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) {
+ type = cmStateEnums::UNINITIALIZED;
}
return cmCacheEntryTypes[type];
}
-cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(const char* s)
+cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
+ const std::string& s)
{
cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
StringToCacheEntryType(s, type);
return type;
}
-bool cmState::StringToCacheEntryType(const char* s,
+bool cmState::StringToCacheEntryType(const std::string& s,
cmStateEnums::CacheEntryType& type)
{
- int i = 0;
- while (cmCacheEntryTypes[i]) {
- if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
+ for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
+ if (s == cmCacheEntryTypes[i]) {
type = static_cast<cmStateEnums::CacheEntryType>(i);
return true;
}
- ++i;
}
return false;
}
bool cmState::IsCacheEntryType(std::string const& key)
{
- for (int i = 0; cmCacheEntryTypes[i]; ++i) {
- if (key == cmCacheEntryTypes[i]) {
+ for (const std::string& i : cmCacheEntryTypes) {
+ if (key == i) {
return true;
}
}
@@ -1006,12 +1007,12 @@ bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
bool flag = false;
if (regQuoted.find(entry)) {
var = regQuoted.match(1);
- type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
+ type = cmState::StringToCacheEntryType(regQuoted.match(2));
value = regQuoted.match(3);
flag = true;
} else if (reg.find(entry)) {
var = reg.match(1);
- type = cmState::StringToCacheEntryType(reg.match(2).c_str());
+ type = cmState::StringToCacheEntryType(reg.match(2));
value = reg.match(3);
flag = true;
}
diff --git a/Source/cmState.h b/Source/cmState.h
index cd871b9..a744266 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -70,10 +70,12 @@ public:
cmStateSnapshot const& originSnapshot);
cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot);
- static cmStateEnums::CacheEntryType StringToCacheEntryType(const char*);
- static bool StringToCacheEntryType(const char*,
+ static cmStateEnums::CacheEntryType StringToCacheEntryType(
+ const std::string&);
+ static bool StringToCacheEntryType(const std::string&,
cmStateEnums::CacheEntryType& type);
- static const char* CacheEntryTypeToString(cmStateEnums::CacheEntryType);
+ static const std::string& CacheEntryTypeToString(
+ cmStateEnums::CacheEntryType);
static bool IsCacheEntryType(std::string const& key);
bool LoadCache(const std::string& path, bool internal,