diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-12-30 15:09:46 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2014-01-06 17:46:44 (GMT) |
commit | 802a28fc5e19136b947b2f7d136de31c1d10b578 (patch) | |
tree | 1c3e13b743830a9ec2a42b49165d2536843afdfb /Source/cmStandardIncludes.h | |
parent | dc08199848c20c7f76a68dbf54a85c736809ac57 (diff) | |
download | CMake-802a28fc5e19136b947b2f7d136de31c1d10b578.zip CMake-802a28fc5e19136b947b2f7d136de31c1d10b578.tar.gz CMake-802a28fc5e19136b947b2f7d136de31c1d10b578.tar.bz2 |
Add cmHasLiteralSuffix API.
Diffstat (limited to 'Source/cmStandardIncludes.h')
-rw-r--r-- | Source/cmStandardIncludes.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index eb6e52f..ebfa8f9 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -391,6 +391,22 @@ inline bool cmHasLiteralPrefixImpl(const char* str1, 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; +} + #if defined(_MSC_VER) && _MSC_VER < 1300 \ || defined(__GNUC__) && __GNUC__ < 3 \ || defined(__BORLANDC__) @@ -402,6 +418,9 @@ inline bool cmHasLiteralPrefixImpl(const char* str1, #define cmHasLiteralPrefix(STR1, STR2) \ cmHasLiteralPrefixImpl(STR1, "" STR2 "", sizeof(STR2) - 1) +#define cmHasLiteralSuffix(STR1, STR2) \ + cmHasLiteralSuffixImpl(STR1, "" STR2 "", sizeof(STR2) - 1) + #else template<typename T, size_t N> @@ -417,6 +436,12 @@ bool cmHasLiteralPrefix(T str1, const char (&str2)[N]) return cmHasLiteralPrefixImpl(str1, str2, N - 1); } +template<typename T, size_t N> +bool cmHasLiteralSuffix(T str1, const char (&str2)[N]) +{ + return cmHasLiteralSuffixImpl(str1, str2, N - 1); +} + #endif struct cmStrCmp { |