int find_and_replace(string search, string replace, string &phrase){
int num_of_replaces = 0;
for (int temp = 0; temp < phrase.size(); temp++) {
if (tolower(phrase[temp]) == search[0]) {
bool found = true;
for (int temp2 = temp + 1, stemp = 1; temp2 < phrase.size() && stemp < search.size(); stemp++, temp2++) {
if (tolower(phrase[temp2]) != search[stemp])
found = false;
}
if (found) {
for (int temp2 = temp, stemp = 0; temp2 < temp + search.size(); stemp++, temp2++) {
phrase[temp2] = replace[stemp % replace.size()];
}
temp+= search.size() - 1;
num_of_replaces++;
}
}
}
return num_of_replaces;
}
Then stopped and realized... this is horrible.
Haha I'm working on my censorship and testing out the speed of several methods. So far I haven't made a useful algorithm. But has anyone had any censoring experience? Care to share some experience?
A rope eh, looks like I'm off to do some research =)
This is actually going to be implemented on individual devices so my server doesn't have to handle censorship and users can have personalized blacklists so I'm not really worried a ton about size, and I'm unfortunately going to have to port everything to objective-c...