summaryrefslogtreecommitdiff
path: root/zen/zstring.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2015-10-02 14:55:19 +0200
committerDaniel Wilhelm <daniel@wili.li>2015-10-02 14:55:19 +0200
commit46fc289a8776ba253e97d01d6948fb1031ea1973 (patch)
treeb16a99c60f21b04c001f29862bf2ee16ae3a0e00 /zen/zstring.h
parent6.15 (diff)
downloadFreeFileSync-46fc289a8776ba253e97d01d6948fb1031ea1973.tar.gz
FreeFileSync-46fc289a8776ba253e97d01d6948fb1031ea1973.tar.bz2
FreeFileSync-46fc289a8776ba253e97d01d6948fb1031ea1973.zip
7.0
Diffstat (limited to 'zen/zstring.h')
-rw-r--r--zen/zstring.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/zen/zstring.h b/zen/zstring.h
index 0610a27f..7dcfbb69 100644
--- a/zen/zstring.h
+++ b/zen/zstring.h
@@ -68,12 +68,12 @@ typedef zen::Zbase<Zchar, zen::StorageRefCountThreadSafe, AllocatorFreeStoreChec
//Compare filepaths: Windows does NOT distinguish between upper/lower-case, while Linux DOES
int cmpFileName(const Zstring& lhs, const Zstring& rhs);
-struct LessFilename //case-insensitive on Windows, case-sensitive on Linux
+struct LessFilePath //case-insensitive on Windows, case-sensitive on Linux
{
bool operator()(const Zstring& lhs, const Zstring& rhs) const { return cmpFileName(lhs, rhs) < 0; }
};
-struct EqualFilename //case-insensitive on Windows, case-sensitive on Linux
+struct EqualFilePath //case-insensitive on Windows, case-sensitive on Linux
{
bool operator()(const Zstring& lhs, const Zstring& rhs) const { return cmpFileName(lhs, rhs) == 0; }
};
@@ -85,10 +85,35 @@ struct EqualFilename //case-insensitive on Windows, case-sensitive on Linux
inline
Zstring appendSeparator(Zstring path) //support rvalue references!
{
- return zen::endsWith(path, FILE_NAME_SEPARATOR) ? path : (path += FILE_NAME_SEPARATOR);
+ return zen::endsWith(path, FILE_NAME_SEPARATOR) ? path : (path += FILE_NAME_SEPARATOR); //returning a by-value parameter implicitly converts to r-value!
}
+inline
+Zstring getFileExtension(const Zstring& filePath)
+{
+ const Zstring shortName = afterLast(filePath, FILE_NAME_SEPARATOR); //returns the whole string if term not found
+
+ return contains(shortName, Zchar('.')) ?
+ afterLast(filePath, Zchar('.')) :
+ Zstring();
+}
+
+
+inline
+bool pathStartsWith(const Zstring& str, const Zstring& prefix)
+{
+ return str.size() >= prefix.size() &&
+ EqualFilePath()(Zstring(str.begin(), str.begin() + prefix.size()), prefix);
+}
+
+
+inline
+bool pathEndsWith(const Zstring& str, const Zstring& postfix)
+{
+ return str.size() >= postfix.size() &&
+ EqualFilePath()(Zstring(str.end() - postfix.size(), str.end()), postfix);
+}
bgstack15