mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-14 02:22:50 +00:00
good good study, day day up!
This commit is contained in:
62
tools/mktable.go
Normal file
62
tools/mktable.go
Normal file
@@ -0,0 +1,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)
|
||||
}
|
Reference in New Issue
Block a user