blob: 17c0d0114e17c8ae49b67e6125898860c67ee3be (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package NET.worlds.network;
import java.util.StringTokenizer;
import java.util.Vector;
public class FilthyPhrase {
private long compareValue;
private Vector<String> filthyWords;
private String rawData;
public FilthyPhrase(String phrase) {
this.rawData = new String(phrase);
this.filthyWords = new Vector<String>();
StringTokenizer st = new StringTokenizer(phrase, "\t\n\r.,;'\"!?*:/()[]{} ,「」『』《》?【】。!、;:", true);
if (st.hasMoreTokens()) {
String firstToken = st.nextToken().toLowerCase();
this.compareValue = firstToken.hashCode();
this.filthyWords.addElement(firstToken);
}
while (st.hasMoreTokens()) {
String nextWord = st.nextToken();
this.filthyWords.addElement(nextWord.toLowerCase());
}
}
public boolean check(String toCheck) {
StringTokenizer st = new StringTokenizer(toCheck, "\t\n\r.,;'\"!?*:/()[]{} ,「」『』《》?【】。!、;:", true);
for (int idx = 0; idx < this.filthyWords.size(); idx++) {
if (!st.hasMoreTokens()) {
return false;
}
String token = st.nextToken().toLowerCase();
String comparator = this.filthyWords.elementAt(idx);
if (comparator.compareTo(token) != 0) {
return false;
}
}
return true;
}
public String getReplacement() {
String funnyChars = new String("$!@%#@&*!%#@%!@#$%@#@!@%!@#$%*&%$!");
String retVal = new String();
for (int idx = 0; idx < this.filthyWords.size(); idx++) {
int numChars = this.filthyWords.elementAt(idx).length();
new String();
String replacementWord;
if (numChars > 1) {
replacementWord = funnyChars.substring(0, numChars);
} else {
replacementWord = this.filthyWords.elementAt(idx);
}
retVal = retVal + replacementWord;
}
return retVal;
}
public long size() {
return this.filthyWords.size();
}
public long compareValue() {
return this.compareValue;
}
public String firstWord() {
return this.filthyWords.size() > 0 ? this.filthyWords.elementAt(0) : new String("");
}
public String asString() {
return this.rawData;
}
}
|