diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStandardIncludes.h | 26 |
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 { |