diff options
| author | horus | 2020-04-19 18:35:27 +0200 |
|---|---|---|
| committer | horus | 2020-04-19 18:35:27 +0200 |
| commit | 8d3be0d8b623a405990448a5ea4fe471ab735ed7 (patch) | |
| tree | 227a325b7a5972996fb499614a1913693de7a49f /chinese.go | |
| parent | 5902524fb85aaf760f3e6a6695b2390868a7bd06 (diff) | |
| download | ghrss-8d3be0d8b623a405990448a5ea4fe471ab735ed7.tar.gz | |
Update to get spoken language and minor upgrade the github handling.
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 +} |
