-
Notifications
You must be signed in to change notification settings - Fork 14
/
filter.go
53 lines (47 loc) · 1.38 KB
/
filter.go
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
package sx
type Filter interface {
// Excludes 用于设置需要排除的内容,主要用于忽略敏感词中间的特殊字符
// 比如:
// 将中线(-)设置为排除内容,同时将 "今天" 设置为敏感词
// 匹配的时候, "今天" 和 "今-天" 都将被判定为敏感词
Excludes(items ...rune)
// Contains 用于检测是否有敏感词:如果有敏感词,返回 true;如果没有敏感词,返回 false;
Contains(text string) bool
// FindFirst 用于查找出第一个敏感词
FindFirst(text string) string
// FindAll 用于查找出所有敏感词
FindAll(text string) []string
// Replace 用于替换敏感词
Replace(text string, replace rune) string
}
func clear(r rune) rune {
if r >= 65 && r <= 90 {
// 大写字母转换成小写字母
r += 32
} else if r >= 65313 && r <= 65338 {
// 大写英文全角转换成小写字母
r = 97 + (r - 65313)
} else if r >= 65345 && r <= 65370 {
// 小写英文全角转换成小写字母
r = 97 + (r - 65345)
} else if r >= 65280 && r <= 65375 {
// 其它全角转换成半角
r = 32 + (r - 65280)
} else {
//8216: 39, // '
//8217: 39, // '
//8220: 34, // "
//8221: 34, // "
//12290: 46, // .
//12304: 91, // [
//12305: 93, // ]
//65281: 33, // !
//65288: 40, // (
//65289: 41, // )
//65292: 44, // ,
//65306: 58, // :
//65307: 59, // ;
//65311: 63, // ?
}
return r
}