summaryrefslogtreecommitdiff
path: root/Source/cmState.cxx
diff options
context:
space:
mode:
authorVitaly Stakhovsky <vvs31415@gitlab.org>2020-01-01 08:00:00 -0500
committerVitaly Stakhovsky <vvs31415@gitlab.org>2020-01-02 07:56:34 -0500
commit232d5bc3339b81170bba940ebad9513a19ceaffb (patch)
tree3fe61328d20eb97d1bc80d674a5602385abe7848 /Source/cmState.cxx
parent47a907413bb8aa2394a3003c90775b402b53d35a (diff)
downloadcmake-232d5bc3339b81170bba940ebad9513a19ceaffb.tar.gz
cmState: more members will use std::string
Diffstat (limited to 'Source/cmState.cxx')
-rw-r--r--Source/cmState.cxx35
1 files changed, 18 insertions, 17 deletions
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 72f663d860..9d83a7296f 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;
}