diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2016-10-29 11:41:53 +0200 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2016-10-29 11:41:53 +0200 |
commit | 7302bb4484d517a72cdffbd13ec7a9f2324cde01 (patch) | |
tree | 17d2964c6768d49510206836a496fb1802a63e08 /zen/zstring.h | |
parent | 8.5 (diff) | |
download | FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.tar.gz FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.tar.bz2 FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.zip |
8.6
Diffstat (limited to 'zen/zstring.h')
-rw-r--r-- | zen/zstring.h | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/zen/zstring.h b/zen/zstring.h index 792b92db..902da80e 100644 --- a/zen/zstring.h +++ b/zen/zstring.h @@ -23,7 +23,7 @@ //"The reason for all the fuss above" - Loki/SmartPtr //a high-performance string for interfacing with native OS APIs in multithreaded contexts -using Zstring = zen::Zbase<Zchar, zen::StorageRefCountThreadSafe, zen::AllocatorOptimalSpeed>; +using Zstring = zen::Zbase<Zchar>; int cmpStringNoCase(const wchar_t* lhs, size_t lhsLen, const wchar_t* rhs, size_t rhsLen); @@ -95,6 +95,9 @@ bool pathEndsWith(const S& str, const T& postfix) } +template <class S, class T, class U> +S pathReplaceCpy(const S& str, const T& oldTerm, const U& newTerm, bool replaceAll = true); + @@ -195,6 +198,41 @@ int cmpFilePath(const char* lhs, size_t lhsLen, const char* rhs, size_t rhsLen) #endif +template <class S, class T, class U> inline +S pathReplaceCpy(const S& str, const T& oldTerm, const U& newTerm, bool replaceAll) +{ + assert(!contains(str, Zchar('\0'))); + +#if defined ZEN_WIN || defined ZEN_MAC + using namespace zen; + + S strU = makeUpperCopy(str); //S required to be a string class + S oldTermU = makeUpperCopy<S>(oldTerm); //[!] T not required to be a string class + assert(strLength(strU ) == strLength(str )); + assert(strLength(oldTermU) == strLength(oldTerm)); + + replace(strU, oldTermU, Zchar('\0'), replaceAll); + + S output; + + size_t i = 0; + for (auto c : strU) + if (c == Zchar('\0')) + { + output += newTerm; + i += oldTermU.size(); + } + else + output += str[i++]; + + return output; + +#elif defined ZEN_LINUX + return replaceCpy(str, oldTerm, newTerm, replaceAll); +#endif +} + + //--------------------------------------------------------------------------- //ZEN macro consistency checks: #ifdef ZEN_WIN |