Added desctructive replace_all for std::string

This commit is contained in:
Bob Polis 2021-07-02 11:37:54 +02:00
parent ea9bcb2fee
commit 884bbfc681
2 changed files with 16 additions and 0 deletions

View File

@ -106,6 +106,18 @@ map<string, string> sc::parse_ini_file(const string& path)
return result; return result;
} }
void sc::replace_all(const std::string& what, const std::string& replacement, std::string& target) {
std::string::size_type pos = std::string::npos;
std::string::size_type from = 0;
do {
pos = target.find(what, from);
if (pos != std::string::npos) {
target.replace(pos, what.length(), replacement);
from = pos + replacement.length();
}
} while (pos != std::string::npos);
}
string sc::str_replace(const string& what, const string& replacement, const string& target) string sc::str_replace(const string& what, const string& replacement, const string& target)
{ {
string result; string result;

View File

@ -36,6 +36,10 @@ namespace sc {
const std::wstring& replacement, const std::wstring& replacement,
const std::wstring& target); const std::wstring& target);
void replace_all (const std::string& what,
const std::string& replacement,
std::string& target);
bool file_exists (const std::string& path); bool file_exists (const std::string& path);
std::string file_get_contents (const std::string& path); std::string file_get_contents (const std::string& path);