cmValue: add IsInternallyOn methods

This commit is contained in:
Marc Chevrier 2021-09-21 17:13:14 +02:00
parent cc56dc7468
commit edf67dd039
4 changed files with 38 additions and 18 deletions

View File

@ -218,15 +218,6 @@ std::string cmCatViews(std::initializer_list<cm::string_view> views)
return result;
}
bool cmIsInternallyOn(cm::string_view val)
{
return (val.size() == 4) && //
(val[0] == 'I' || val[0] == 'i') && //
(val[1] == '_') && //
(val[2] == 'O' || val[2] == 'o') && //
(val[3] == 'N' || val[3] == 'n');
}
bool cmStrToLong(const char* str, long* value)
{
errno = 0;

View File

@ -224,20 +224,17 @@ std::string cmWrap(char prefix, Range const& rng, char suffix,
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
bool cmIsInternallyOn(cm::string_view val);
inline bool cmIsInternallyOn(cm::string_view val)
{
return cmValue::IsInternallyOn(val);
}
inline bool cmIsInternallyOn(const char* val)
{
if (!val) {
return false;
}
return cmIsInternallyOn(cm::string_view(val));
return cmValue::IsInternallyOn(val);
}
inline bool cmIsInternallyOn(cmValue val)
{
if (!val) {
return false;
}
return cmIsInternallyOn(*val);
return val.IsInternallyOn();
}
/** Check for non-empty Property/Variable value. */

View File

@ -73,11 +73,21 @@ bool cmValue::IsOff(cm::string_view value) noexcept
return IsNOTFOUND(value);
}
bool cmValue::IsNOTFOUND(cm::string_view value) noexcept
{
return (value == "NOTFOUND"_s) || cmHasSuffix(value, "-NOTFOUND"_s);
}
bool cmValue::IsInternallyOn(cm::string_view value) noexcept
{
return (value.size() == 4) && //
(value[0] == 'I' || value[0] == 'i') && //
(value[1] == '_') && //
(value[2] == 'O' || value[2] == 'o') && //
(value[3] == 'N' || value[3] == 'n');
}
int cmValue::Compare(cmValue value) const noexcept
{
if (this->Value == nullptr && !value) {

View File

@ -85,6 +85,17 @@ public:
return this->Value == nullptr || this->Value->empty();
}
/**
* Does a string indicates that CMake/CPack/CTest internally
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
bool IsInternallyOn() const noexcept
{
return this->Value != nullptr &&
cmValue::IsInternallyOn(cm::string_view(*this->Value));
}
bool IsSet() const noexcept
{
return !this->IsEmpty() && !this->IsNOTFOUND();
@ -131,6 +142,17 @@ public:
}
static bool IsEmpty(cm::string_view value) noexcept { return value.empty(); }
/**
* Does a string indicates that CMake/CPack/CTest internally
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
static bool IsInternallyOn(const char* value) noexcept
{
return value != nullptr && IsInternallyOn(cm::string_view(value));
}
static bool IsInternallyOn(cm::string_view) noexcept;
private:
static std::string Empty;
const std::string* Value = nullptr;