Added more Util tests and str-wstr related changes to util functions
This commit is contained in:
+11
-20
@@ -1,23 +1,14 @@
|
||||
#include <corecrt.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
|
||||
std::string nb::find_and_replace(const std::string& original, const std::string& find, const std::string& replace) {
|
||||
std::string ret = original;
|
||||
|
||||
std::size_t find_len = find.length();
|
||||
std::size_t replace_len = replace.length();
|
||||
std::size_t currpos = 0;
|
||||
std::size_t lastpos = 0;
|
||||
while(true) {
|
||||
lastpos = currpos;
|
||||
currpos = original.find(find, lastpos);
|
||||
if (currpos == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
ret = ret.erase(currpos, find_len);
|
||||
ret = ret.insert(currpos, replace);
|
||||
currpos += replace_len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#ifdef _NB_TARGET_WINDOWS
|
||||
const std::string NEWLINE("\r\n");
|
||||
const std::wstring WNEWLINE(L"\r\n");
|
||||
#endif // _NB_TARGET_WINDOWS
|
||||
#ifdef _NB_TARGET_LINUX
|
||||
const std::string NEWLINE("\n");
|
||||
const std::wstring WNEWLINE(L"\n");
|
||||
#endif // _NB_TARGET_LINUX
|
||||
|
||||
Reference in New Issue
Block a user