blob: 48ccd5ea5ca2f34f6720f046ce43a9e026f612f0 (
plain)
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
|
package main
import (
"unicode"
)
func IsChinese(str string) bool {
count_chinese := 0
count_no_chinese := 0
for _, char := range str {
if unicode.Is(unicode.Han, char) {
count_chinese++
} else {
if !unicode.IsSpace(char) {
count_no_chinese++
}
}
}
// >= 10% of the text is chinese
if count_chinese >= count_no_chinese/10 {
return true
}
return false
}
|