-
Notifications
You must be signed in to change notification settings - Fork 0
/
blank-cjchars.go
70 lines (67 loc) · 1.23 KB
/
blank-cjchars.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"bufio"
"io"
"os"
"unicode"
. "github.com/Des-Nerger/sinojapsubs-tools/commonrangetables"
)
func main() {
blankSequence := "囗" //口◻⬜▢◯
switch len(os.Args) {
case 1:
case 2:
blankSequence = os.Args[1]
default:
os.Stderr.WriteString("!(1 <= len(os.Args) <= 2)")
return
}
br, bw := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
for {
r, _, err := br.ReadRune()
switch err {
case nil: // Do nothing
case io.EOF:
bw.Flush()
return
default:
panic(err)
}
switch r {
//case 'ー', '~', '・', '・':
case '…':
bw.WriteString("...")
case '!':
bw.WriteByte('!')
case '?':
bw.WriteByte('?')
case '~':
bw.WriteByte('~')
case '・', '・':
bw.WriteString(blankSequence)
default:
if unicode.In(r, unicode.Pi, unicode.Ps) {
bw.WriteByte('[')
} else if unicode.In(r, unicode.Pf, unicode.Pe) {
bw.WriteByte(']')
} else if !unicode.In(r,
unicode.Hiragana,
unicode.Katakana,
unicode.Han,
FullwidthAlphaNum,
/*
unicode.Latin,
unicode.Punct,
unicode.Symbol,
*/
unicode.Lm,
unicode.Bopomofo,
unicode.Sk,
) {
bw.WriteRune(r)
} else {
bw.WriteString(blankSequence)
}
}
}
}