Added more Util tests and str-wstr related changes to util functions

This commit is contained in:
NaifBanana
2026-05-18 01:35:27 -05:00
parent 450c793d71
commit 31ea554cd1
3 changed files with 145 additions and 33 deletions
+11 -20
View File
@@ -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