Bugfix: cope with an empty stopwords list.
This commit is contained in:
@@ -21,10 +21,14 @@
|
|||||||
|
|
||||||
package com.threerings.crowd.chat.client;
|
package com.threerings.crowd.chat.client;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import com.samskivert.util.RandomUtil;
|
import com.samskivert.util.RandomUtil;
|
||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
@@ -43,12 +47,11 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
*/
|
*/
|
||||||
public static String comicChars (int length)
|
public static String comicChars (int length)
|
||||||
{
|
{
|
||||||
StringBuilder buf = new StringBuilder();
|
char[] chars = new char[length];
|
||||||
for (int ii=0; ii < length; ii++) {
|
for (int ii=0; ii < length; ii++) {
|
||||||
buf.append(RandomUtil.pickRandom(COMIC_CHARS));
|
chars[ii] = RandomUtil.pickRandom(COMIC_CHARS);
|
||||||
}
|
}
|
||||||
|
return new String(chars);
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,20 +205,11 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
*/
|
*/
|
||||||
protected void configureStopWords (String stopWords)
|
protected void configureStopWords (String stopWords)
|
||||||
{
|
{
|
||||||
StringTokenizer st = new StringTokenizer(stopWords);
|
List<String> patterns = Lists.newArrayList();
|
||||||
|
for (StringTokenizer st = new StringTokenizer(stopWords); st.hasMoreTokens(); ) {
|
||||||
String pattern = "";
|
patterns.add(getStopWordRegexp(st.nextToken()));
|
||||||
while (st.hasMoreTokens()) {
|
|
||||||
if ("".equals(pattern)) {
|
|
||||||
pattern += "(";
|
|
||||||
} else {
|
|
||||||
pattern += "|";
|
|
||||||
}
|
|
||||||
pattern += getStopWordRegexp(st.nextToken());
|
|
||||||
}
|
}
|
||||||
pattern += ")";
|
setStopPattern("(" + Joiner.on('|').join(patterns) + ")");
|
||||||
|
|
||||||
setStopPattern(pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,5 +244,5 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
protected String[] _vernacular;
|
protected String[] _vernacular;
|
||||||
|
|
||||||
/** Comic replacement characters. */
|
/** Comic replacement characters. */
|
||||||
protected static final String[] COMIC_CHARS = { "!", "@", "#", "%", "&", "*" };
|
protected static final Character[] COMIC_CHARS = { '!', '@', '#', '%', '&', '*' };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user