Made errors mostly work as hoped

This commit is contained in:
NaifBanana
2026-06-11 04:24:06 -05:00
parent d448b6724a
commit 0b473c0f8a
13 changed files with 284 additions and 142 deletions
+23
View File
@@ -0,0 +1,23 @@
#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;
}