Make CurseFilter work on codepoints, not characters, when capitalizing the
beginning of words in those times when 2 bytes just aren't enough for a letter. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5219 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -41,17 +41,15 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
public enum Mode { DROP, COMIC, VERNACULAR, UNFILTERED; }
|
public enum Mode { DROP, COMIC, VERNACULAR, UNFILTERED; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a curse filter. The curse words should be a string in the
|
* Creates a curse filter. The curse words should be a string in the following format:
|
||||||
* following format:
|
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* *penis*=John_Thomas shit*=barnacle muff=britches
|
* *penis*=John_Thomas shit*=barnacle muff=britches
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* The key/value pairs are separated by spaces, * matches word characters
|
* The key/value pairs are separated by spaces, * matches word characters and the value after
|
||||||
* and the value after the = is the string into which to convert the text
|
* the = is the string into which to convert the text when converting to the vernacular.
|
||||||
* when converting to the vernacular. Underscores in the target string will
|
* Underscores in the target string will be turned into spaces.
|
||||||
* be turned into spaces.
|
|
||||||
*
|
*
|
||||||
* <p> And stopWords should be in the following format:
|
* <p> And stopWords should be in the following format:
|
||||||
*
|
*
|
||||||
@@ -68,8 +66,7 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client will need to provide a way to look up our current chat filter
|
* The client will need to provide a way to look up our current chat filter mode.
|
||||||
* mode.
|
|
||||||
*/
|
*/
|
||||||
public abstract Mode getFilterMode ();
|
public abstract Mode getFilterMode ();
|
||||||
|
|
||||||
@@ -106,10 +103,10 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
|
|
||||||
case VERNACULAR:
|
case VERNACULAR:
|
||||||
String vernacular = _vernacular[ii];
|
String vernacular = _vernacular[ii];
|
||||||
if (Character.isUpperCase(m.group(2).charAt(0))) {
|
if (Character.isUpperCase(m.group(2).codePointAt(0))) {
|
||||||
vernacular = new String(
|
int firstCharLen = Character.charCount(vernacular.codePointAt(0));
|
||||||
Character.toUpperCase(vernacular.charAt(0)) +
|
vernacular = vernacular.substring(0, firstCharLen).toUpperCase() +
|
||||||
vernacular.substring(1));
|
vernacular.substring(firstCharLen);
|
||||||
}
|
}
|
||||||
m.appendReplacement(outbuf,
|
m.appendReplacement(outbuf,
|
||||||
StringUtil.replace(_replacements[ii], " ", vernacular));
|
StringUtil.replace(_replacements[ii], " ", vernacular));
|
||||||
@@ -150,8 +147,8 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
String mapping = st.nextToken();
|
String mapping = st.nextToken();
|
||||||
StringTokenizer st2 = new StringTokenizer(mapping, "=");
|
StringTokenizer st2 = new StringTokenizer(mapping, "=");
|
||||||
if (st2.countTokens() != 2) {
|
if (st2.countTokens() != 2) {
|
||||||
log.warning("Something looks wrong in the x.cursewords " +
|
log.warning("Something looks wrong in the x.cursewords properties (" +
|
||||||
"properties (" + mapping + "), skipping.");
|
mapping + "), skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String curse = st2.nextToken();
|
String curse = st2.nextToken();
|
||||||
@@ -173,8 +170,7 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
s += "$3";
|
s += "$3";
|
||||||
}
|
}
|
||||||
|
|
||||||
String pattern = "\\b" +
|
String pattern = "\\b" + StringUtil.replace(p, " ", "(" + curse + ")") + "\\b";
|
||||||
StringUtil.replace(p, " ", "(" + curse + ")") + "\\b";
|
|
||||||
Pattern pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
|
Pattern pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
|
||||||
_matchers[ii] = pat.matcher("");
|
_matchers[ii] = pat.matcher("");
|
||||||
_replacements[ii] = s;
|
_replacements[ii] = s;
|
||||||
@@ -219,8 +215,7 @@ public abstract class CurseFilter implements ChatFilter
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A matcher that will always cause a message to be dropped if it
|
/** A matcher that will always cause a message to be dropped if it matches. */
|
||||||
* matches. */
|
|
||||||
protected Matcher _stopMatcher;
|
protected Matcher _stopMatcher;
|
||||||
|
|
||||||
/** Matchers for each curseword. */
|
/** Matchers for each curseword. */
|
||||||
|
|||||||
Reference in New Issue
Block a user