Censor Function

Started by DizzasTeR, Dec 25, 2015, 06:31 AM

Previous topic - Next topic

DizzasTeR

Censor Function

Original Author: @S.L.C

Since S.L.C mentioned he was going to post an update which supports case sensitivity but I noticed that till now its not been done so I decided to do it myself. A few guys also wanted to see case sensitivity in this one but I think it was forgotten. Anyhow here is an updated one, totally tested, works like a charm, the features are:

- No more lower cased strings
- Supports case sensitive words

local _CENSOR_WORDS = [
    "poop", "cunt",
    "jerk", "crap",
    "shit", "faggot"
    // More words follow ...
];

local _CENSOR_MASK = "****************************************************************";

function Censor( text )
{
    if (typeof text != "string") return "";
 
    local str = text, pos = null;

    foreach( word in _CENSOR_WORDS )
    {
        while (str.tolower().find(word) != null) {
        pos = str.tolower().find(word);
        str = format(@"%s%s%s",
        str.slice(0, pos),
        _CENSOR_MASK.slice(0, word.len()),
        str.slice(pos + word.len()));
}
    }
return str;
}

Here is an example output:
function onScriptLoad() {
print( Censor( "WOW! This crap now supports CASE sensitive SHIT as well!" ) );
}

# Output

[SCRIPT]  WOW! This **** now supports CASE sensitive **** as well!

~ Regards,
Doom_Kill3R

.

The reason I haven't kept my promise to implement this function is because it's almost useless. If I want to say bad words I can keep obfuscating them enough to get past this verification and while still being readable. And to be able to catch all those bad words one would have to add a ridiculous amount of strings to test against.

And adding more stress on a server just to have these flashy features isn't worth it. Imagine having few thousand censored words and going through them on every chat message. It's not much for today's hardware to handle but it doesn't make much sense to have it either.

While this is a good scripting exercise it's not as useful as it looks. One day when you've gathered enough experience in programming and begin to look at things from a different perspective you'll turn back to my words and see I wasn't wrong.
.