summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-07-26 11:29:31 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-07-26 11:30:45 (GMT)
commitc23c4ed9cf912e265e1070507905b3dbc495a210 (patch)
treec6cdcac257f4c00f4c65158965fed8a52ff264d4 /Source/cmAlgorithms.h
parent9f23c91919945f8158ef5bc2512aefaa418de0da (diff)
parent4ff0bb054b65ac332fed3272afac8142599b6464 (diff)
downloadCMake-c23c4ed9cf912e265e1070507905b3dbc495a210.zip
CMake-c23c4ed9cf912e265e1070507905b3dbc495a210.tar.gz
CMake-c23c4ed9cf912e265e1070507905b3dbc495a210.tar.bz2
Merge topic 'IsON_IsOFF_string_view'
4ff0bb054b cmSystemTools: Make IsInternallyOn, IsON and IsOff cm::string_view based 65d3ea2c7f cmAlgorithms: Make cmHasLiteral{Prefix,Suffix} cm::string_view based Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3598
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h52
1 files changed, 14 insertions, 38 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index b4b480b..cf71052 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -19,44 +19,6 @@
#include <utility>
#include <vector>
-inline bool cmHasLiteralPrefixImpl(const std::string& str1, const char* str2,
- size_t N)
-{
- return strncmp(str1.c_str(), str2, N) == 0;
-}
-
-inline bool cmHasLiteralPrefixImpl(const char* str1, const char* str2,
- size_t N)
-{
- return strncmp(str1, str2, N) == 0;
-}
-
-inline bool cmHasLiteralSuffixImpl(const std::string& str1, const char* str2,
- size_t N)
-{
- size_t len = str1.size();
- return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
-}
-
-inline bool cmHasLiteralSuffixImpl(const char* str1, const char* str2,
- size_t N)
-{
- size_t len = strlen(str1);
- return len >= N && strcmp(str1 + len - N, str2) == 0;
-}
-
-template <typename T, size_t N>
-bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N])
-{
- return cmHasLiteralPrefixImpl(str1, str2, N - 1);
-}
-
-template <typename T, size_t N>
-bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N])
-{
- return cmHasLiteralSuffixImpl(str1, str2, N - 1);
-}
-
struct cmStrCmp
{
cmStrCmp(const char* test)
@@ -327,6 +289,13 @@ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix)
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])
+{
+ return cmHasPrefix(str, cm::string_view(prefix, N - 1));
+}
+
/** Returns true if string @a str ends with the character @a suffix. **/
inline bool cmHasSuffix(cm::string_view str, char suffix)
{
@@ -340,6 +309,13 @@ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix)
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])
+{
+ return cmHasSuffix(str, cm::string_view(suffix, N - 1));
+}
+
/** Removes an existing suffix character of from the string @a str. **/
inline void cmStripSuffixIfExists(std::string& str, char suffix)
{