Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / godoc / static / gen.go
1 // Copyright 2014 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 package static
6
7 //go:generate go run makestatic.go
8
9 import (
10         "bytes"
11         "fmt"
12         "go/format"
13         "io/ioutil"
14         "unicode"
15 )
16
17 var files = []string{
18         "analysis/call3.png",
19         "analysis/call-eg.png",
20         "analysis/callers1.png",
21         "analysis/callers2.png",
22         "analysis/chan1.png",
23         "analysis/chan2a.png",
24         "analysis/chan2b.png",
25         "analysis/error1.png",
26         "analysis/help.html",
27         "analysis/ident-def.png",
28         "analysis/ident-field.png",
29         "analysis/ident-func.png",
30         "analysis/ipcg-func.png",
31         "analysis/ipcg-pkg.png",
32         "analysis/typeinfo-pkg.png",
33         "analysis/typeinfo-src.png",
34         "callgraph.html",
35         "dirlist.html",
36         "error.html",
37         "example.html",
38         "godoc.html",
39         "godocs.js",
40         "images/minus.gif",
41         "images/plus.gif",
42         "images/treeview-black-line.gif",
43         "images/treeview-black.gif",
44         "images/treeview-default-line.gif",
45         "images/treeview-default.gif",
46         "images/treeview-gray-line.gif",
47         "images/treeview-gray.gif",
48         "implements.html",
49         "jquery.js",
50         "jquery.treeview.css",
51         "jquery.treeview.edit.js",
52         "jquery.treeview.js",
53         "methodset.html",
54         "package.html",
55         "packageroot.html",
56         "play.js",
57         "playground.js",
58         "search.html",
59         "searchcode.html",
60         "searchdoc.html",
61         "searchtxt.html",
62         "style.css",
63 }
64
65 // Generate reads a set of files and returns a file buffer that declares
66 // a map of string constants containing contents of the input files.
67 func Generate() ([]byte, error) {
68         buf := new(bytes.Buffer)
69         fmt.Fprintf(buf, "%v\n\n%v\n\npackage static\n\n", license, warning)
70         fmt.Fprintf(buf, "var Files = map[string]string{\n")
71         for _, fn := range files {
72                 b, err := ioutil.ReadFile(fn)
73                 if err != nil {
74                         return b, err
75                 }
76                 fmt.Fprintf(buf, "\t%q: ", fn)
77                 appendQuote(buf, b)
78                 fmt.Fprintf(buf, ",\n\n")
79         }
80         fmt.Fprintln(buf, "}")
81         return format.Source(buf.Bytes())
82 }
83
84 // appendQuote is like strconv.AppendQuote, but we avoid the latter
85 // because it changes when Unicode evolves, breaking gen_test.go.
86 func appendQuote(out *bytes.Buffer, data []byte) {
87         out.WriteByte('"')
88         for _, b := range data {
89                 if b == '\\' || b == '"' {
90                         out.WriteByte('\\')
91                         out.WriteByte(b)
92                 } else if b <= unicode.MaxASCII && unicode.IsPrint(rune(b)) && !unicode.IsSpace(rune(b)) {
93                         out.WriteByte(b)
94                 } else {
95                         fmt.Fprintf(out, "\\x%02x", b)
96                 }
97         }
98         out.WriteByte('"')
99 }
100
101 const warning = `// Code generated by "makestatic"; DO NOT EDIT.`
102
103 const license = `// Copyright 2013 The Go Authors. All rights reserved.
104 // Use of this source code is governed by a BSD-style
105 // license that can be found in the LICENSE file.`