Open alexey-malov opened 8 years ago
std::string FindAndReplace(const std::string & subject, const std::string & search, const std::string & replace)
{
std::string result;
std::string window = "";
for (auto ch : subject)
{
window += ch;
if (window.size() == search.size())
{
result += window == search ? replace : window;
window = "";
}
}
result += window;
return result;
}
BOOST_AUTO_TEST_CASE(search_for_multi_char_string)
{
BOOST_CHECK_EQUAL(FindAndReplace("hello world", "world", "world-world"), "hello world-world");
}