2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-06-22 03:16:14 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace utils
|
|
|
|
{
|
|
|
|
|
|
|
|
// replaces all occurences of <match> in <src> with <replacement>
|
|
|
|
|
|
|
|
std::string replace(std::string src,
|
|
|
|
const std::string& match,
|
|
|
|
const std::string& replacement)
|
|
|
|
{
|
|
|
|
for(size_t pos = src.find(match);
|
|
|
|
pos != std::string::npos;
|
|
|
|
pos = src.find(match, pos + replacement.size()))
|
|
|
|
src.erase(pos, match.length()).insert(pos, replacement);
|
|
|
|
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|