diff options
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 22 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 6e57bb6..5abac99 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -936,6 +936,28 @@ char* SystemTools::ReplaceChars(char* str, const char *toreplace, char replaceme return str; } +// Returns if string starts with another string +bool vtkString::StringStartsWith(const char* str1, const char* str2) +{ + if (!str1 || !str2) + { + return false; + } + size_t len1 = strlen(str1), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1, str2, len2) ? true : false +} + +// Returns if string ends with another string +bool vtkString::StringEndsWith(const char* str1, const char* str2) +{ + if (!str1 || !str2) + { + return false; + } + size_t len1 = strlen(str1), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1 + (len1 - len2), str2, len2) ? true : false; +} + // Returns a pointer to the last occurence of str2 in str1 const char* SystemTools::FindLastString(const char* str1, const char* str2) { diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 5a84279..2a06f6d 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -155,6 +155,12 @@ public: static char* ReplaceChars(char* str, const char *toreplace,char replacement); /** + * Returns true if str1 starts or ends with str2 + */ + static bool StringStartsWith(const char* str1, const char* str2); + static bool StringEndsWith(const char* str1, const char* str2); + + /** * Returns a pointer to the last occurence of str2 in str1 */ static const char* FindLastString(const char* str1, const char* str2); |