Created
December 17, 2009 21:29
-
-
Save sipple/259044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Text.RegularExpressions; | |
namespace website.lib | |
{ | |
public enum BadwordSensitivity | |
{ | |
low = 1, medium = 2, high = 3 | |
} | |
/// <summary> | |
/// Summary description for badwords. | |
/// </summary> | |
public class badwords | |
{ | |
BadwordSensitivity level; | |
SortedList offensive; | |
public badwords(): this(BadwordSensitivity.high) | |
{ | |
} | |
public badwords ( BadwordSensitivity v ) | |
{ | |
this.level = v; | |
this.addbadwords(); | |
} | |
/// <summary> | |
/// Checks supplied text against list of offensive words | |
/// | |
/// </summary> | |
/// <param name="userText">The text to check</param> | |
/// <returns>true if text is acceptable</returns> | |
public bool litmusTest(string userText) | |
{ | |
bool retval = true; | |
Regex rx = new Regex( @"[,.!@#$%^&*()+\]\[\{=\-':;<>?/]" ); | |
string t = rx.Replace( userText, "" ); | |
string[] ta = t.Split( new char[] { ' ' } ); | |
for ( int x = 0; x < ta.Length; x++ ) | |
{ | |
// iterate thru all the words and see if they're in the badwords list | |
if ( offensive.Contains(ta[x].ToLower() ) ) | |
{ | |
// we found a potentially bad word | |
if ( ( (int) offensive[ ta[x].ToLower()]) <= (int) level ) | |
{ | |
// we only need to find one | |
retval = false; | |
break; | |
} | |
} | |
} | |
return retval; | |
} | |
private void addbadwords() | |
{ | |
this.offensive = new SortedList(); | |
// set items to 1 to make them trip at all levels | |
// less offensive words can be a 2 and | |
// the least offensive words should be 3 | |
offensive.Add("fuck", 1 ); | |
offensive.Add("pussy", 1 ); | |
offensive.Add("cunt", 1 ); | |
offensive.Add("cock", 1 ); | |
offensive.Add("suck", 3 ); | |
offensive.Add("sucks", 3 ); | |
offensive.Add("shit", 2 ); | |
offensive.Add("asshole", 2 ); | |
offensive.Add("prick", 3 ); | |
offensive.Add("bitch", 3 ); | |
offensive.Add("bastard", 3 ); | |
offensive.Add("screw", 3 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment