-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrokecounts.go
67 lines (59 loc) · 1.53 KB
/
strokecounts.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
package unihand
import (
"fmt"
)
func init() {
// The field 'kRSUnicode' is included with the IRGSources document for some reason
fileFilters = append(fileFilters, fileFilter{
Filename: "Unihan_RadicalStrokeCounts.txt",
RecordFilter: radicalStrokeCount,
}, fileFilter{
Filename: "Unihan_IRGSources.txt",
RecordFilter: radicalStrokeCount,
})
fileFilters = append(fileFilters, fileFilter{
Filename: "Unihan_DictionaryLikeData.txt",
RecordFilter: totalStrokes,
})
}
func radicalStrokeCount(char *Character, code uint32, fields []string) error {
if len(fields) < 2 {
return fmt.Errorf("got invalid record [%s]", fields)
}
if fields[0] == "kRSKangXi" || fields[0] == "kRSUnicode" {
var rsc RScount
_, err := fmt.Sscanf(fields[1], "%d.%d", &rsc.Radical, &rsc.Additional)
if err != nil {
_, err := fmt.Sscanf(fields[1], "%d'.%d", &rsc.Radical, &rsc.Additional)
if err != nil {
return err
} else {
rsc.SimplifiedVersion = true
}
}
if fields[0] == "kRSKangXi" {
char.RadicalStrokeCounts.KangXi = rsc
} else if fields[0] == "kRSUnicode" {
char.RadicalStrokeCounts.Unicode = rsc
}
}
return nil
}
func totalStrokes(char *Character, code uint32, fields []string) error {
if len(fields) < 2 {
return fmt.Errorf("got invalid record [%s]", fields)
}
if fields[0] == "kTotalStrokes" {
var hans, hant uint8
n, _ := fmt.Sscan(fields[1], &hans, &hant)
if n >= 1 {
char.Strokes = hans
if n == 1 {
char.StrokesTW = hans
} else {
char.StrokesTW = hant
}
}
}
return nil
}