From e5d3c045d5b64e903210e94ea0e3a8d69e263019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 5 May 2016 22:55:05 -0700 Subject: [PATCH] Added string replace all. --- include/bx/string.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/bx/string.h b/include/bx/string.h index 640de06..937f15d 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -386,6 +386,23 @@ namespace bx va_end(argList); } + /// Replace all instances of substring. + template + inline Ty replaceAll(const Ty& _str, const char* _from, const char* _to) + { + Ty str = _str; + size_t startPos = 0; + const size_t fromLen = strlen(_from); + const size_t toLen = strlen(_to); + while ( (startPos = str.find(_from, startPos) ) != Ty::npos) + { + str.replace(startPos, fromLen, _to); + startPos += toLen; + } + + return str; + } + /// Extract base file name from file path. inline const char* baseName(const char* _filePath) {