forked from gopl-zh/gopl-zh.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mktable.go
62 lines (50 loc) · 1.25 KB
/
mktable.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
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ingore
package main
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"unicode/utf8"
)
func main() {
f, err := os.Open("./TSCharacters.txt")
if err != nil {
log.Fatal("open failed:", err)
}
defer f.Close()
br := bufio.NewReader(f)
var out bytes.Buffer
fmt.Fprintf(&out, `
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Auto generated by go generate, DO NOT EDIT !!!
package main
var _TSCharactersMap = map[rune]rune{
`[1:])
for i := 0; i < 1<<20; i++ {
data, isPrefix, err := br.ReadLine()
if err != nil || isPrefix {
break
}
if !utf8.ValidString(string(data)) {
continue
}
line := strings.Replace(string(data), "\t", " ", -1)
ss := strings.Split(string(line), " ")
if len(ss) >= 2 {
tw := strings.TrimSpace(ss[0])
zh := strings.TrimSpace(ss[1])
fmt.Fprintf(&out, "\t'%s': '%s',\n", tw, zh)
}
}
fmt.Fprintf(&out, "}\n")
ioutil.WriteFile("z_TSCharacters.go", []byte(out.Bytes()), 0666)
}