Update vulgarity processor

This commit is contained in:
Braydon 2024-06-06 21:48:39 -04:00
parent 6db88e8932
commit 6d5d96ce5c

@ -27,17 +27,18 @@ public final class VulgarityProcessor extends TextProcessor {
/** /**
* Substitutions for characters in profane words. * Substitutions for characters in profane words.
*/ */
private static final Map<Character, Character> charSubstitutions = Collections.synchronizedMap(new HashMap<>()); private static final Map<Character, List<Character>> charSubstitutions = Collections.synchronizedMap(new HashMap<>());
static { // Populate char substitutions static { // Populate char substitutions
charSubstitutions.put('3', 'e'); charSubstitutions.put('e', Collections.singletonList('3'));
charSubstitutions.put('1', 'i'); charSubstitutions.put('i', List.of('1', '!'));
charSubstitutions.put('!', 'i'); charSubstitutions.put('a', List.of('4', '@'));
charSubstitutions.put('@', 'a'); charSubstitutions.put('t', List.of('7'));
charSubstitutions.put('7', 't'); charSubstitutions.put('o', List.of('0'));
charSubstitutions.put('0', 'o'); charSubstitutions.put('s', List.of('5', '$'));
charSubstitutions.put('5', 's'); charSubstitutions.put('b', List.of('8'));
charSubstitutions.put('8', 'b'); charSubstitutions.put('g', Collections.singletonList('q'));
charSubstitutions.put('$', 's'); charSubstitutions.put('u', Collections.singletonList('v'));
charSubstitutions.put('1', Collections.singletonList('!'));
} }
public VulgarityProcessor() { public VulgarityProcessor() {
@ -117,7 +118,11 @@ public final class VulgarityProcessor extends TextProcessor {
char lowerChar = Character.toLowerCase(character); char lowerChar = Character.toLowerCase(character);
exactWordRegex.append(lowerChar); exactWordRegex.append(lowerChar);
if (charSubstitutions.containsKey(lowerChar)) { if (charSubstitutions.containsKey(lowerChar)) {
obfuscatedWordRegex.append('[').append(lowerChar).append(charSubstitutions.get(lowerChar)).append(']'); StringBuilder chars = new StringBuilder(Character.toString(lowerChar));
for (Character substitution : charSubstitutions.get(lowerChar)) {
chars.append(substitution);
}
obfuscatedWordRegex.append('[').append(chars).append(']');
} else { } else {
obfuscatedWordRegex.append(lowerChar); obfuscatedWordRegex.append(lowerChar);
} }