summaryrefslogtreecommitdiffstats
path: root/Source/cmStringAlgorithms.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmStringAlgorithms.h')
-rw-r--r--Source/cmStringAlgorithms.h102
1 files changed, 41 insertions, 61 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 6b458ec..492e588 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -15,24 +15,11 @@
#include <cm/string_view>
#include "cmRange.h"
+#include "cmValue.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])
@@ -107,6 +94,13 @@ std::vector<std::string> cmTokenize(cm::string_view str, cm::string_view sep);
*/
void cmExpandList(cm::string_view arg, std::vector<std::string>& argsOut,
bool emptyArgs = false);
+inline void cmExpandList(cmValue arg, std::vector<std::string>& argsOut,
+ bool emptyArgs = false)
+{
+ if (arg) {
+ cmExpandList(*arg, argsOut, emptyArgs);
+ }
+}
/**
* Expand out any arguments in the string range [@a first, @a last) that have
@@ -128,6 +122,14 @@ void cmExpandLists(InputIt first, InputIt last,
*/
std::vector<std::string> cmExpandedList(cm::string_view arg,
bool emptyArgs = false);
+inline std::vector<std::string> cmExpandedList(cmValue arg,
+ bool emptyArgs = false)
+{
+ if (!arg) {
+ return {};
+ }
+ return cmExpandedList(*arg, emptyArgs);
+}
/**
* Same as cmExpandList but a new vector is created containing the expanded
@@ -175,6 +177,10 @@ public:
cmAlphaNum(unsigned long long int val);
cmAlphaNum(float val);
cmAlphaNum(double val);
+ cmAlphaNum(cmValue value)
+ : View_(*value)
+ {
+ }
cm::string_view View() const { return this->View_; }
@@ -213,53 +219,6 @@ std::string cmWrap(char prefix, Range const& rng, char suffix,
sep);
}
-/**
- * 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 cmIsInternallyOn(cm::string_view val);
-inline bool cmIsInternallyOn(const char* val)
-{
- if (!val) {
- return false;
- }
- return cmIsInternallyOn(cm::string_view(val));
-}
-
-/** Return true if value is NOTFOUND or ends in -NOTFOUND. */
-bool cmIsNOTFOUND(cm::string_view val);
-
-/**
- * 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(const char* val)
-{
- return val && cmIsOn(cm::string_view(val));
-}
-inline bool cmIsOn(std::string const* val)
-{
- return val && cmIsOn(*val);
-}
-
-/**
- * Does a string indicate a false or off value ? Note that this is
- * not the same as !IsOn(...) because there are a number of
- * ambiguous values such as "/usr/local/bin" a path will result in
- * 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(const char* val)
-{
- return !val || cmIsOff(cm::string_view(val));
-}
-inline bool cmIsOff(std::string const* val)
-{
- return !val || cmIsOff(*val);
-}
-
/** Returns true if string @a str starts with the character @a prefix. */
inline bool cmHasPrefix(cm::string_view str, char prefix)
{
@@ -273,6 +232,16 @@ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix)
}
/** Returns true if string @a str starts with string @a prefix. */
+inline bool cmHasPrefix(cm::string_view str, cmValue prefix)
+{
+ if (!prefix) {
+ return false;
+ }
+
+ return str.compare(0, prefix->size(), *prefix) == 0;
+}
+
+/** Returns true if string @a str starts with string @a prefix. */
template <size_t N>
inline bool cmHasLiteralPrefix(cm::string_view str, const char (&prefix)[N])
{
@@ -293,6 +262,17 @@ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix)
}
/** Returns true if string @a str ends with string @a suffix. */
+inline bool cmHasSuffix(cm::string_view str, cmValue suffix)
+{
+ if (!suffix) {
+ return false;
+ }
+
+ return str.size() >= suffix->size() &&
+ str.compare(str.size() - suffix->size(), suffix->size(), *suffix) == 0;
+}
+
+/** Returns true if string @a str ends with string @a suffix. */
template <size_t N>
inline bool cmHasLiteralSuffix(cm::string_view str, const char (&suffix)[N])
{