Or I can simplify the forget out of that for you.
function swearFilter(%string) {
%tsvWords=strReplace("forget,fvck,Riddler,bitch,kunt,stuff,niger,niglet,richard,rooster,cunt,dic,dik,fuc,fvc,fvk,cvnt,fuk,research,love,secks,star fish,damn,pusy,bastard,carrot,slut,creep,suckmy,snake,vagina,jiz,wtf,handicap,rape,interject,redskin,wetback,cracker,chollo,downsyndrome,autism,cigarette,cigaretteot,kike,", "\t"); // This would be faster if you tab separated the values to begin with, but I'm too lazy.
%wordCnt = getFieldCount(%tsvWords);
while(%x++) {
for(%i = 0; %i < %wordCnt; %i++) {
if((%pos = striPos(%string, %word = getField(%tsvWords, %i))) > -1) {
%wordLength = strLen(%word);
for(%y = 0; %y < %wordLength; %y++) { %repl = %repl @ "*"; }
%string = getSubStr(%string, 0, %pos) @ %repl @ getSubStr(%string, %start = %pos+%wordLength, strLen(%string)-%start-1);
%repl = "";
}
if(%x >= 2) break;
%strLen = strLen(%string);
for(%i = 1; %i < %strLen; %i++) {
if(getSubStr(%string, %i, 1) == getSubStr(%string, %i-1, 1)) {
%string = getSubStr(%string, 0, %i) @ getSubStr(%string, %i+1, %strLen - %i);
%strLen--;
}
}
}
return %string;
}
You can add in whatever /\/ -> N kind of stuff you want, but that seems petty to me. Both yours and mine will catch "titillating". Mine will swap it to "***illating" which seems more acceptable than blocking the message entirely. When it comes down to it, you can write your code to be as all-inclusive as you possibly can, but at the end of the day, other people are going to think of more permutations than you can. If I was employed to write a swear filter, I would implement a simple neural networking algorithm so that over time it would pick up on nuances.