size_t pos = 0;
// This sting will keep original case (capitals etc..)
std::string filteredString = str;
// the str string will be lowercase. To make matching easier from database
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
// Oldstr must search for lower case only, as that is what the string we are searching trough is.
std::transform(oldStr.begin(), oldStr.end(), oldStr.begin(), ::tolower);
for (std::string::iterator itr = str.begin(); itr != str.end(); ++itr)
{
if (ispunct(*itr) || isspace(*itr))
m_FillerCharContainer.insert(std::make_pair<char, size_t>(*itr, pos));
// We loop the lowercase string.
while((pos = str.find(oldStr, pos)) != std::string::npos)
{
size_t oldPos = pos;
// We replace equally in both strings, so they keep in sync on next iteration (if any next iteration).
str.replace(pos, oldStr.length(), newStr);
filteredString.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
for (FillerCharContainer::iterator itr2 = m_FillerCharContainer.begin(); itr2 != m_FillerCharContainer.end();)
{
if (itr2->second >= oldPos + oldStr.length())
itr2->second += newStr.length() - oldStr.length();