utilies

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 61d6be1b5524dd0575abb16bda7e1cdfd230d070
parent 57325add5d63c587344ca10853fe087d3c8b0b26
Author: Taco-C <perian.forod@gmail.com>
Date:   Wed,  1 Jul 2020 22:52:01 +0200

Add hangrep.go

Diffstat:
Ahangrep.go | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/hangrep.go b/hangrep.go @@ -0,0 +1,28 @@ +// From standard input, filter out single chinese characters to standard output. + +package main + +import ( + "bufio" + "fmt" + "os" + "unicode" +) + +func main() { + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + text := scanner.Text() + runes := []rune(text) + if len(runes) != 1 { + continue + } + if isHanzi(runes[0]) { + fmt.Println(text) + } + } +} + +func isHanzi(r rune) bool { + return unicode.Is(unicode.Han, r) +}