diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-04 15:08:17 +0200 |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-08 16:19:08 +0200 |
commit | e5cd39ca80c8c234118ded33a1576c1be281aa9e (patch) | |
tree | 0494dad04188959dd6cefc9497688718ff88006b /Source/cmStringAlgorithms.h | |
parent | 350065bb855a26692ed6af04870f144ae1f6a886 (diff) | |
download | cmake-e5cd39ca80c8c234118ded33a1576c1be281aa9e.tar.gz |
cmProp: refactoring: transform alias in class
To handle safely the values used by CMake variables and properties,
introduce the class cmProp as a replacement from the simple pointer
to std::string instance.
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r-- | Source/cmStringAlgorithms.h | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 6b458ec52c..531678ad22 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -14,25 +14,12 @@ #include <cm/string_view> +#include "cmProperty.h" #include "cmRange.h" /** String range type. */ using cmStringRange = cmRange<std::vector<std::string>::const_iterator>; -/** Check for non-empty string. */ -inline bool cmNonempty(const char* str) -{ - return str && *str; -} -inline bool cmNonempty(cm::string_view str) -{ - return !str.empty(); -} -inline bool cmNonempty(std::string const* str) -{ - return str && !str->empty(); -} - /** Returns length of a literal string. */ template <size_t N> constexpr size_t cmStrLen(const char (&/*str*/)[N]) @@ -175,6 +162,10 @@ public: cmAlphaNum(unsigned long long int val); cmAlphaNum(float val); cmAlphaNum(double val); + cmAlphaNum(cmProp value) + : View_(*value) + { + } cm::string_view View() const { return this->View_; } @@ -227,20 +218,44 @@ inline bool cmIsInternallyOn(const char* val) return cmIsInternallyOn(cm::string_view(val)); } +/** Check for non-empty Property/Variable value. */ +inline bool cmNonempty(cm::string_view val) +{ + return !cmProp::IsEmpty(val); +} +inline bool cmNonempty(const char* val) +{ + return !cmProp::IsEmpty(val); +} +inline bool cmNonempty(cmProp val) +{ + return !val.IsEmpty(); +} + /** Return true if value is NOTFOUND or ends in -NOTFOUND. */ -bool cmIsNOTFOUND(cm::string_view val); +inline bool cmIsNOTFOUND(cm::string_view val) +{ + return cmProp::IsNOTFOUND(val); +} +inline bool cmIsNOTFOUND(cmProp val) +{ + return val.IsNOTFOUND(); +} /** * Does a string indicate a true or ON value? This is not the same as ifdef. */ -bool cmIsOn(cm::string_view val); +inline bool cmIsOn(cm::string_view val) +{ + return cmProp::IsOn(val); +} inline bool cmIsOn(const char* val) { - return val && cmIsOn(cm::string_view(val)); + return cmProp::IsOn(val); } -inline bool cmIsOn(std::string const* val) +inline bool cmIsOn(cmProp val) { - return val && cmIsOn(*val); + return val.IsOn(); } /** @@ -250,14 +265,17 @@ inline bool cmIsOn(std::string const* val) * IsON and IsOff both returning false. Note that the special path * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true. */ -bool cmIsOff(cm::string_view val); +inline bool cmIsOff(cm::string_view val) +{ + return cmProp::IsOff(val); +} inline bool cmIsOff(const char* val) { - return !val || cmIsOff(cm::string_view(val)); + return cmProp::IsOff(val); } -inline bool cmIsOff(std::string const* val) +inline bool cmIsOff(cmProp val) { - return !val || cmIsOff(*val); + return val.IsOff(); } /** Returns true if string @a str starts with the character @a prefix. */ |