OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / internal / gen.go
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // +build ignore
6
7 package main
8
9 import (
10         "log"
11
12         "golang.org/x/text/internal/gen"
13         "golang.org/x/text/language"
14         "golang.org/x/text/unicode/cldr"
15 )
16
17 func main() {
18         r := gen.OpenCLDRCoreZip()
19         defer r.Close()
20
21         d := &cldr.Decoder{}
22         data, err := d.DecodeZip(r)
23         if err != nil {
24                 log.Fatalf("DecodeZip: %v", err)
25         }
26
27         w := gen.NewCodeWriter()
28         defer w.WriteGoFile("tables.go", "internal")
29
30         // Create parents table.
31         parents := make([]uint16, language.NumCompactTags)
32         for _, loc := range data.Locales() {
33                 tag := language.MustParse(loc)
34                 index, ok := language.CompactIndex(tag)
35                 if !ok {
36                         continue
37                 }
38                 parentIndex := 0 // und
39                 for p := tag.Parent(); p != language.Und; p = p.Parent() {
40                         if x, ok := language.CompactIndex(p); ok {
41                                 parentIndex = x
42                                 break
43                         }
44                 }
45                 parents[index] = uint16(parentIndex)
46         }
47
48         w.WriteComment(`
49         Parent maps a compact index of a tag to the compact index of the parent of
50         this tag.`)
51         w.WriteVar("Parent", parents)
52 }