From c016fab8e8a12137e5e694c1eb2f4c53c8931a55 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Tue, 9 Jun 2009 21:00:21 +0000 Subject: [PATCH] Break a few parts out for use in subclasses git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5821 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/client/CurseFilter.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/client/CurseFilter.java b/src/java/com/threerings/crowd/chat/client/CurseFilter.java index f875bae69..a13f7b2bb 100644 --- a/src/java/com/threerings/crowd/chat/client/CurseFilter.java +++ b/src/java/com/threerings/crowd/chat/client/CurseFilter.java @@ -192,12 +192,27 @@ public abstract class CurseFilter implements ChatFilter } else { pattern += "|"; } - pattern += "\\b" + StringUtil.replace(st.nextToken(), "*", "[A-Za-z]*") + "\\b"; + pattern += getStopWordRegexp(st.nextToken()); } pattern += ")"; - Pattern pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); - _stopMatcher = pat.matcher(""); + setStopPattern(pattern); + } + + /** + * Sets our stop word matcher to one for the given regular expression. + */ + protected void setStopPattern (String pattern) + { + _stopMatcher = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE).matcher(""); + } + + /** + * Turns a naughty word into a regular expression to catch it. + */ + protected String getStopWordRegexp (String word) + { + return "\\b" + StringUtil.replace(word, "*", "[A-Za-z]*") + "\\b"; } /**