summaryrefslogtreecommitdiff
path: root/zen/zstring.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/zstring.h')
-rw-r--r--zen/zstring.h40
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
bgstack15