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/cmProperty.cxx | |
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/cmProperty.cxx')
-rw-r--r-- | Source/cmProperty.cxx | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx new file mode 100644 index 0000000000..d012630de3 --- /dev/null +++ b/Source/cmProperty.cxx @@ -0,0 +1,113 @@ + +#include "cmProperty.h" + +#include <string> + +#include <cmext/string_view> + +#include "cmStringAlgorithms.h" + +std::string cmProp::Empty; + +bool cmProp::IsOn(cm::string_view value) noexcept +{ + switch (value.size()) { + case 1: + return value[0] == '1' || value[0] == 'Y' || value[0] == 'y'; + case 2: + return // + (value[0] == 'O' || value[0] == 'o') && // + (value[1] == 'N' || value[1] == 'n'); + case 3: + return // + (value[0] == 'Y' || value[0] == 'y') && // + (value[1] == 'E' || value[1] == 'e') && // + (value[2] == 'S' || value[2] == 's'); + case 4: + return // + (value[0] == 'T' || value[0] == 't') && // + (value[1] == 'R' || value[1] == 'r') && // + (value[2] == 'U' || value[2] == 'u') && // + (value[3] == 'E' || value[3] == 'e'); + default: + break; + } + + return false; +} + +bool cmProp::IsOff(cm::string_view value) noexcept +{ + switch (value.size()) { + case 0: + return true; + case 1: + return value[0] == '0' || value[0] == 'N' || value[0] == 'n'; + case 2: + return // + (value[0] == 'N' || value[0] == 'n') && // + (value[1] == 'O' || value[1] == 'o'); + case 3: + return // + (value[0] == 'O' || value[0] == 'o') && // + (value[1] == 'F' || value[1] == 'f') && // + (value[2] == 'F' || value[2] == 'f'); + case 5: + return // + (value[0] == 'F' || value[0] == 'f') && // + (value[1] == 'A' || value[1] == 'a') && // + (value[2] == 'L' || value[2] == 'l') && // + (value[3] == 'S' || value[3] == 's') && // + (value[4] == 'E' || value[4] == 'e'); + case 6: + return // + (value[0] == 'I' || value[0] == 'i') && // + (value[1] == 'G' || value[1] == 'g') && // + (value[2] == 'N' || value[2] == 'n') && // + (value[3] == 'O' || value[3] == 'o') && // + (value[4] == 'R' || value[4] == 'r') && // + (value[5] == 'E' || value[5] == 'e'); + default: + break; + } + + return IsNOTFOUND(value); +} +bool cmProp::IsNOTFOUND(cm::string_view value) noexcept +{ + return (value == "NOTFOUND"_s) || cmHasSuffix(value, "-NOTFOUND"_s); +} + +int cmProp::Compare(cmProp value) const noexcept +{ + if (this->Value == nullptr && !value) { + return 0; + } + if (this->Value == nullptr) { + return -1; + } + if (!value) { + return 1; + } + return this->Value->compare(*value); +} + +int cmProp::Compare(cm::string_view value) const noexcept +{ + if (this->Value == nullptr && value.data() == nullptr) { + return 0; + } + if (this->Value == nullptr) { + return -1; + } + if (value.data() == nullptr) { + return 1; + } + return cm::string_view(*this->Value).compare(value); +} + +std::ostream& operator<<(std::ostream& o, cmProp v) +{ + o << *v; + return o; +} |