summaryrefslogtreecommitdiff
path: root/chinese.go
diff options
context:
space:
mode:
authorhorus2020-04-19 18:35:27 +0200
committerhorus2020-04-19 18:35:27 +0200
commit8d3be0d8b623a405990448a5ea4fe471ab735ed7 (patch)
tree227a325b7a5972996fb499614a1913693de7a49f /chinese.go
parent5902524fb85aaf760f3e6a6695b2390868a7bd06 (diff)
downloadghrss-8d3be0d8b623a405990448a5ea4fe471ab735ed7.tar.gz
Update to get spoken language and minor upgrade the github handling.
Diffstat (limited to 'chinese.go')
-rw-r--r--chinese.go25
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
+}