public String filter ( String msg , Name otherUser , boolean outgoing ) { // first, check against the drop-always list _stopMatcher . reset ( msg ) ; if ( _stopMatcher . find ( ) ) { return null ; } // then see what kind of curse filtering the user has configured Mode level = getFilterMode ( ) ; if ( level == Mode . UNFILTERED ) { return msg ; } StringBuffer inbuf = new StringBuffer ( msg ) ; StringBuffer outbuf = new StringBuffer ( msg . length ( ) ) ; for ( int ii = 0 , nn = _matchers . length ; ii < nn ; ii ++ ) { Matcher m = _matchers [ ii ] ; m . reset ( inbuf ) ; while ( m . find ( ) ) { switch ( level ) { case DROP : return null ; case COMIC : m . appendReplacement ( outbuf , _replacements [ ii ] . replace ( " " , comicChars ( _comicLength [ ii ] ) ) ) ; break ; case VERNACULAR : String vernacular = _vernacular [ ii ] ; if ( Character . isUpperCase ( m . group ( 2 ) . codePointAt ( 0 ) ) ) { int firstCharLen = Character . charCount ( vernacular . codePointAt ( 0 ) ) ; vernacular = vernacular . substring ( 0 , firstCharLen ) . toUpperCase ( ) + vernacular . substring ( firstCharLen ) ; } m . appendReplacement ( outbuf , _replacements [ ii ] . replace ( " " , vernacular ) ) ; break ; case UNFILTERED : // We returned the msg unadulterated above in this case, so it should be // impossible to wind up here, but let's enumerate it so we can let the compiler // scream about missing enum values in a switch log . warning ( "Omg? We're trying to filter chat even though we're unfiltered?" ) ; break ; } } if ( outbuf . length ( ) == 0 ) { // optimization: if we didn't find a match, jump to the next // pattern without doing any StringBuilder jimmying continue ; } m . appendTail ( outbuf ) ; // swap the buffers around and clear the output StringBuffer temp = inbuf ; inbuf = outbuf ; outbuf = temp ; outbuf . setLength ( 0 ) ; } return inbuf . toString ( ) ; }
from interface ChatFilter