summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-13 04:41:58 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-13 04:41:58 +0000
commit1afedebf29ed9aefacffc2aa5f7dfb4b04d70f0b (patch)
tree49f608627f133611f9d17e458ce71315ceb6b8dd /Common/interface
parentFixed https://github.com/DiligentGraphics/DiligentCore/issues/2 (make '_sampl... (diff)
downloadDiligentCore-1afedebf29ed9aefacffc2aa5f7dfb4b04d70f0b.tar.gz
DiligentCore-1afedebf29ed9aefacffc2aa5f7dfb4b04d70f0b.zip
Improved StrCmpSuff() to allow optional suffix
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/StringTools.h57
1 files changed, 48 insertions, 9 deletions
diff --git a/Common/interface/StringTools.h b/Common/interface/StringTools.h
index 6506bbb2..2ce9729d 100644
--- a/Common/interface/StringTools.h
+++ b/Common/interface/StringTools.h
@@ -98,27 +98,66 @@ inline int StrCmpNoCase(const char* Str1, const char* Str2)
}
// Returns true if RefStr == Str + Suff
-inline bool StrCmpSuff(const char *RefStr, const char *Str, const char *Suff)
+// If NoSuffixAllowed == true, also returns true if RefStr == Str
+inline bool StrCmpSuff(const char* RefStr, const char* Str, const char* Suff, bool NoSuffixAllowed = false)
{
- VERIFY_EXPR(RefStr != nullptr && Str!= nullptr && Suff != nullptr);
- if(RefStr==nullptr)
+ VERIFY_EXPR(RefStr != nullptr && Str!= nullptr);
+ if (RefStr==nullptr)
return false;
- const auto *r = RefStr;
- const auto *s = Str;
- for(; *r!=0 && *s!=0; ++r, ++s)
+ const auto* r = RefStr;
+ const auto* s = Str;
+ // abc_def abc
+ // ^ ^
+ // r s
+ for (; *r != 0 && *s != 0; ++r, ++s)
{
if (*r != *s)
+ {
+ // abc_def abx
+ // ^ ^
+ // r s
return false;
+ }
}
- if( *s != 0 )
+ if (*s != 0)
{
+ // abc abc_def
+ // ^ ^
+ // r s
VERIFY_EXPR(*r == 0);
return false;
}
-
- return strcmp(r, Suff) == 0;
+ else
+ {
+ // abc_def abc
+ // ^ ^
+ // r s
+
+ if (NoSuffixAllowed && *r == 0)
+ {
+ // abc abc _def
+ // ^ ^
+ // r s
+ return true;
+ }
+
+ if (Suff != nullptr)
+ {
+ // abc_def abc _def
+ // ^ ^ ^
+ // r s Suff
+ return strcmp(r, Suff) == 0;
+ }
+ else
+ {
+ // abc abc abc_def abc
+ // ^ ^ or ^ ^
+ // r s r s
+ return *r == 0;
+ }
+ }
}
inline void StrToLowerInPlace(std::string &str)