com.threerings.crowd.chat.client
Class CurseFilter

java.lang.Object
  extended by com.threerings.crowd.chat.client.CurseFilter
All Implemented Interfaces:
ChatFilter

public abstract class CurseFilter
extends Object
implements ChatFilter

A chat filter that can filter out curse words from user chat.


Nested Class Summary
static class CurseFilter.Mode
          Indicates how messages should be handled.
 
Field Summary
protected  int[] _comicLength
          Length of comic-y replacements for each curseword.
protected  Matcher[] _matchers
          Matchers for each curseword.
protected  String[] _replacements
          Replacements.
protected  Matcher _stopMatcher
          A matcher that will always cause a message to be dropped if it matches.
protected  String[] _vernacular
          Replacements for each curseword "in the vernacular".
protected static String[] COMIC_CHARS
          Comic replacement characters.
 
Constructor Summary
CurseFilter(String curseWords, String stopWords)
          Creates a curse filter.
 
Method Summary
protected  String comicChars(int length)
          Return a comicy replacement of the specified length.
protected  void configureCurseWords(String curseWords)
          Configure the curse word portion of our filtering.
protected  void configureStopWords(String stopWords)
          Configure the words that will stop.
 String filter(String msg, Name otherUser, boolean outgoing)
          Filter a chat message.
abstract  CurseFilter.Mode getFilterMode()
          The client will need to provide a way to look up our current chat filter mode.
protected  String getStopWordRegexp(String word)
          Turns a naughty word into a regular expression to catch it.
protected  void setStopPattern(String pattern)
          Sets our stop word matcher to one for the given regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_stopMatcher

protected Matcher _stopMatcher
A matcher that will always cause a message to be dropped if it matches.


_matchers

protected Matcher[] _matchers
Matchers for each curseword.


_comicLength

protected int[] _comicLength
Length of comic-y replacements for each curseword.


_replacements

protected String[] _replacements
Replacements.


_vernacular

protected String[] _vernacular
Replacements for each curseword "in the vernacular".


COMIC_CHARS

protected static final String[] COMIC_CHARS
Comic replacement characters.

Constructor Detail

CurseFilter

public CurseFilter(String curseWords,
                   String stopWords)
Creates a curse filter. The curse words should be a string in the following format:
 *penis*=John_Thomas shit*=barnacle muff=britches
 
The key/value pairs are separated by spaces, * matches word characters and the value after the = is the string into which to convert the text when converting to the vernacular. Underscores in the target string will be turned into spaces.

And stopWords should be in the following format:

 *faggot* rape rapes raped raping
 
Words are separated by spaces and * matches any other word characters.

Method Detail

getFilterMode

public abstract CurseFilter.Mode getFilterMode()
The client will need to provide a way to look up our current chat filter mode.


filter

public String filter(String msg,
                     Name otherUser,
                     boolean outgoing)
Description copied from interface: ChatFilter
Filter a chat message.

Specified by:
filter in interface ChatFilter
Parameters:
msg - the message text to be filtered.
otherUser - an optional argument that represents the target or the speaker, depending on 'outgoing', and can be considered in filtering if it is provided.
outgoing - true if the message is going out to the server.
Returns:
the filtered message, or null to block it completely.

configureCurseWords

protected void configureCurseWords(String curseWords)
Configure the curse word portion of our filtering.


configureStopWords

protected void configureStopWords(String stopWords)
Configure the words that will stop.


setStopPattern

protected void setStopPattern(String pattern)
Sets our stop word matcher to one for the given regular expression.


getStopWordRegexp

protected String getStopWordRegexp(String word)
Turns a naughty word into a regular expression to catch it.


comicChars

protected String comicChars(int length)
Return a comicy replacement of the specified length.