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.
17 "golang.org/x/text/internal/gen"
20 type registry struct {
21 XMLName xml.Name `xml:"registry"`
22 Updated string `xml:"updated"`
24 ID string `xml:"id,attr"`
26 Name string `xml:"name"`
28 Type string `xml:"type,attr"`
29 Data string `xml:"data,attr"`
32 Data string `xml:",innerxml"`
34 // Data string `xml:",chardata"`
36 // Data string `xml:",chardata"`
37 } `xml:"description,"`
38 MIB string `xml:"value"`
39 Alias []string `xml:"alias"`
40 MIME string `xml:"preferred_alias"`
46 r := gen.OpenIANAFile("assignments/character-sets/character-sets.xml")
48 if err := xml.NewDecoder(r).Decode(®); err != nil && err != io.EOF {
49 log.Fatalf("Error decoding charset registry: %v", err)
51 if len(reg.Registry) == 0 || reg.Registry[0].ID != "character-sets-1" {
52 log.Fatalf("Unexpected ID %s", reg.Registry[0].ID)
56 fmt.Fprintf(w, "const (\n")
57 for _, rec := range reg.Registry[0].Record {
59 for _, a := range rec.Alias {
60 if strings.HasPrefix(a, "cs") && strings.IndexByte(a, '-') == -1 {
61 // Some of the constant definitions have comments in them. Strip those.
62 constName = strings.Title(strings.SplitN(a[2:], "\n", 2)[0])
68 constName = "HZGB2312" // Not listed as alias for some reason.
70 log.Fatalf("No cs alias defined for %s.", rec.MIB)
74 rec.MIME = fmt.Sprintf(" (MIME: %s)", rec.MIME)
76 fmt.Fprintf(w, "// %s is the MIB identifier with IANA name %s%s.\n//\n", constName, rec.Name, rec.MIME)
77 if len(rec.Desc.Data) > 0 {
79 d := xml.NewDecoder(strings.NewReader(rec.Desc.Data))
90 switch x := t.(type) {
92 attr = "" // Don't need attribute info.
93 a := bytes.Split([]byte(x), []byte("\n"))
95 if b = bytes.TrimSpace(b); len(b) != 0 {
97 fmt.Fprint(w, "\n// ")
100 fmt.Fprintf(w, "%s ", string(b))
103 case xml.StartElement:
104 if x.Name.Local == "xref" {
107 for _, a := range x.Attr {
108 if a.Name.Local == "type" {
109 use = use || a.Value != "person"
111 if a.Name.Local == "data" && use {
123 for _, x := range rec.Xref {
126 fmt.Fprintf(w, "// Reference: %s\n", strings.ToUpper(x.Data))
128 fmt.Fprintf(w, "// Reference: %s\n", x.Data)
131 fmt.Fprintf(w, "%s MIB = %s\n", constName, rec.MIB)
136 gen.WriteGoFile("mib.go", "identifier", w.Bytes())