Browse Source

Merge pull request #1123 from akiyamaneko/patch-3

敏感词工具类SensitiveUtil支持自定义字符过滤规则
Golden Looly 5 years ago
parent
commit
3185664018
1 changed files with 12 additions and 0 deletions
  1. 12 0
      hutool-dfa/src/main/java/cn/hutool/dfa/SensitiveUtil.java

+ 12 - 0
hutool-dfa/src/main/java/cn/hutool/dfa/SensitiveUtil.java

@@ -73,6 +73,18 @@ public final class SensitiveUtil {
 	}
 	
 	/**
+	 * 设置字符过滤规则,通过定义字符串过滤规则,过滤不需要的字符<br>
+	 * 当accept为false时,此字符不参与匹配
+	 *
+	 * @param charFilter 过滤函数
+	 */
+	public static void setCharFilter(Filter<Character> charFilter) {
+		if(charFilter != null) {
+			sensitiveTree.setCharFilter(charFilter);
+		}
+	}
+	
+	/**
 	 * 是否包含敏感词
 	 * @param text 文本
 	 * @return 是否包含