Browse Source

cmValue: add IsInternallyOn methods

Marc Chevrier 4 years ago
parent
commit
edf67dd039
4 changed files with 38 additions and 18 deletions
  1. 0 9
      Source/cmStringAlgorithms.cxx
  2. 6 9
      Source/cmStringAlgorithms.h
  3. 10 0
      Source/cmValue.cxx
  4. 22 0
      Source/cmValue.h

+ 0 - 9
Source/cmStringAlgorithms.cxx

@@ -218,15 +218,6 @@ std::string cmCatViews(std::initializer_list<cm::string_view> views)
   return result;
   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)
 bool cmStrToLong(const char* str, long* value)
 {
 {
   errno = 0;
   errno = 0;

+ 6 - 9
Source/cmStringAlgorithms.h

@@ -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
  * forced this value. This is not the same as On, but this
  * may be considered as "internally switched on".
  * 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)
 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)
 inline bool cmIsInternallyOn(cmValue val)
 {
 {
-  if (!val) {
-    return false;
-  }
-  return cmIsInternallyOn(*val);
+  return val.IsInternallyOn();
 }
 }
 
 
 /** Check for non-empty Property/Variable value.  */
 /** Check for non-empty Property/Variable value.  */

+ 10 - 0
Source/cmValue.cxx

@@ -73,11 +73,21 @@ bool cmValue::IsOff(cm::string_view value) noexcept
 
 
   return IsNOTFOUND(value);
   return IsNOTFOUND(value);
 }
 }
+
 bool cmValue::IsNOTFOUND(cm::string_view value) noexcept
 bool cmValue::IsNOTFOUND(cm::string_view value) noexcept
 {
 {
   return (value == "NOTFOUND"_s) || cmHasSuffix(value, "-NOTFOUND"_s);
   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
 int cmValue::Compare(cmValue value) const noexcept
 {
 {
   if (this->Value == nullptr && !value) {
   if (this->Value == nullptr && !value) {

+ 22 - 0
Source/cmValue.h

@@ -85,6 +85,17 @@ public:
     return this->Value == nullptr || this->Value->empty();
     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
   bool IsSet() const noexcept
   {
   {
     return !this->IsEmpty() && !this->IsNOTFOUND();
     return !this->IsEmpty() && !this->IsNOTFOUND();
@@ -131,6 +142,17 @@ public:
   }
   }
   static bool IsEmpty(cm::string_view value) noexcept { return value.empty(); }
   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:
 private:
   static std::string Empty;
   static std::string Empty;
   const std::string* Value = nullptr;
   const std::string* Value = nullptr;