Added desctructive replace_all for std::string
This commit is contained in:
parent
ea9bcb2fee
commit
884bbfc681
@ -106,6 +106,18 @@ map<string, string> sc::parse_ini_file(const string& path)
|
||||
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 result;
|
||||
|
@ -36,6 +36,10 @@ namespace sc {
|
||||
const std::wstring& replacement,
|
||||
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);
|
||||
|
||||
std::string file_get_contents (const std::string& path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user