summaryrefslogtreecommitdiffstats
path: root/Source/cmStandardIncludes.h
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-11-20 01:12:48 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-11-21 19:53:15 (GMT)
commit7d4b2b2ef36c73c36eefd464fbb17bf34ebdb5fe (patch)
treed434da35097fa8753b5fdab5b08420f51a67a6b5 /Source/cmStandardIncludes.h
parentb7cecfcb21c60a3e9a989dabdd411c306e7b9e51 (diff)
downloadCMake-7d4b2b2ef36c73c36eefd464fbb17bf34ebdb5fe.zip
CMake-7d4b2b2ef36c73c36eefd464fbb17bf34ebdb5fe.tar.gz
CMake-7d4b2b2ef36c73c36eefd464fbb17bf34ebdb5fe.tar.bz2
cmStandardIncludes: Add new cmHasLiteralPrefix function.
This allows avoiding error-prone hard-coding of literal string lengths. Borland is not able to process the template version of this method. Make it use the macro version instead. This means that Borland will also use the macro versions of cmArray*.
Diffstat (limited to 'Source/cmStandardIncludes.h')
-rw-r--r--Source/cmStandardIncludes.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h
index 18d017d..1ccec68 100644
--- a/Source/cmStandardIncludes.h
+++ b/Source/cmStandardIncludes.h
@@ -377,13 +377,31 @@ static thisClass* SafeDownCast(cmObject *c) \
return 0;\
}
+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;
+}
+
#if defined(_MSC_VER) && _MSC_VER < 1300 \
- || defined(__GNUC__) && __GNUC__ < 3
+ || defined(__GNUC__) && __GNUC__ < 3 \
+ || defined(__BORLANDC__)
#define cmArrayBegin(a) a
#define cmArraySize(a) (sizeof(a)/sizeof(*a))
#define cmArrayEnd(a) a + cmArraySize(a)
+#define cmHasLiteralPrefix(STR1, STR2) \
+ cmHasLiteralPrefixImpl(STR1, "" STR2 "", sizeof(STR2) - 1)
+
#else
template<typename T, size_t N>
@@ -393,6 +411,12 @@ const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
template<typename T, size_t N>
size_t cmArraySize(const T (&)[N]) { return N; }
+template<typename T, size_t N>
+bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
+{
+ return cmHasLiteralPrefixImpl(str1, str2, N - 1);
+}
+
#endif
struct cmStrCmp {