-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgentables.go
67 lines (55 loc) · 1.21 KB
/
gentables.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
//+build ignore
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
var buf bytes.Buffer
buf.WriteString("// Code generated by gentables.go. DO NOT EDIT.\n\n")
buf.WriteString("package xmlwriter\n\n")
buf.WriteString("var nameChar = [65536]int8{\n\t")
w := 0
for rn := uint16(0); rn < 0xFFFF; rn++ {
if w == 8 {
buf.WriteString("\n\t")
w = 0
}
if rn == ':' || rn == '_' ||
(rn >= 'A' && rn <= 'Z') ||
(rn >= 'a' && rn <= 'z') ||
(rn >= 0xC0 && rn <= 0xD6) ||
(rn >= 0xD8 && rn <= 0xF6) ||
(rn >= 0xF8 && rn <= 0x2FF) ||
(rn >= 0x370 && rn <= 0x37D) {
buf.WriteString(fmt.Sprintf("0x%x: 1, ", rn))
w++
continue
}
if rn == '-' || rn == '.' || (rn >= '0' && rn <= '9') || rn == 0xB7 ||
(rn >= 0x300 && rn <= 0x36F) ||
(rn >= 0x203F && rn <= 0x2040) {
buf.WriteString(fmt.Sprintf("0x%x: 2, ", rn))
w++
continue
}
}
buf.WriteString("\n}\n")
out := "tables_gen.go"
orig, err := ioutil.ReadFile(out)
if err != nil && !os.IsNotExist(err) {
return err
}
if bytes.Compare(orig, buf.Bytes()) != 0 {
return ioutil.WriteFile(out, buf.Bytes(), 0644)
}
return nil
}