diff options
Diffstat (limited to 'chinese.go')
| -rw-r--r-- | chinese.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/chinese.go b/chinese.go new file mode 100644 index 0000000..48ccd5e --- /dev/null +++ b/chinese.go @@ -0,0 +1,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 +} |
