Debian Codegraph @

resolve.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package yamlscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/
2
3 import (
4 "encoding/base64scip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/"
5 "mathscip-go gomod github.com/golang/go/src go1.15 math/"
6 "regexpscip-go gomod github.com/golang/go/src go1.15 regexp/"
7 "strconvscip-go gomod github.com/golang/go/src go1.15 strconv/"
8 "stringsscip-go gomod github.com/golang/go/src go1.15 strings/"
9 "timescip-go gomod github.com/golang/go/src go1.15 time/"
10 )
11
12 type resolveMapItemscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem# struct {
13 valuescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#value. interface{}
14 tagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#tag. string
15 }
16
17 var resolveTablescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveTable. = make([]byte, 256)
18 var resolveMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMap. = make(map[string]resolveMapItemscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#)
19
20 func initscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/init().() {
21 t := resolveTablescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveTable.
22 t[int('+')] = 'S' // Sign
23 t[int('-')] = 'S'
24 for _, c := range "0123456789" {
25 t[int(c)] = 'D' // Digit
26 }
27 for _, c := range "yYnNtTfFoO~" {
28 t[int(c)] = 'M' // In map
29 }
30 t[int('.')] = '.' // Float (potentially in map)
31
32 var resolveMapList = []struct {
33 v interface{}
34 tag string
35 l []string
36 }{
37 {true, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"y", "Y", "yes", "Yes", "YES"}},
38 {true, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"true", "True", "TRUE"}},
39 {true, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"on", "On", "ON"}},
40 {false, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"n", "N", "no", "No", "NO"}},
41 {false, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"false", "False", "FALSE"}},
42 {false, yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., []string{"off", "Off", "OFF"}},
43 {nil, yaml_NULL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_NULL_TAG., []string{"", "~", "null", "Null", "NULL"}},
44 {mathscip-go gomod github.com/golang/go/src go1.15 math/.NaNscip-go gomod github.com/golang/go/src go1.15 math/NaN().(), yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., []string{".nan", ".NaN", ".NAN"}},
45 {mathscip-go gomod github.com/golang/go/src go1.15 math/.Infscip-go gomod github.com/golang/go/src go1.15 math/Inf().(+1), yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., []string{".inf", ".Inf", ".INF"}},
46 {mathscip-go gomod github.com/golang/go/src go1.15 math/.Infscip-go gomod github.com/golang/go/src go1.15 math/Inf().(+1), yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., []string{"+.inf", "+.Inf", "+.INF"}},
47 {mathscip-go gomod github.com/golang/go/src go1.15 math/.Infscip-go gomod github.com/golang/go/src go1.15 math/Inf().(-1), yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., []string{"-.inf", "-.Inf", "-.INF"}},
48 {"<<", yaml_MERGE_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_MERGE_TAG., []string{"<<"}},
49 }
50
51 m := resolveMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMap.
52 for _, item := range resolveMapList {
53 for _, s := range item.l {
54 m[s] = resolveMapItemscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#{item.v, item.tag}
55 }
56 }
57 }
58
59 const longTagPrefixscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/longTagPrefix. = "tag:yaml.org,2002:"
60
61 func shortTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/shortTag().(tag string) string {
62 // TODO This can easily be made faster and produce less garbage.
63 if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(tag, longTagPrefixscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/longTagPrefix.) {
64 return "!!" + tag[len(longTagPrefixscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/longTagPrefix.):]
65 }
66 return tag
67 }
68
69 func longTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/longTag().(tag string) string {
70 if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(tag, "!!") {
71 return longTagPrefixscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/longTagPrefix. + tag[2:]
72 }
73 return tag
74 }
75
76 func resolvableTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolvableTag().(tag string) bool {
77 switch tag {
78 case "", yaml_STR_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_STR_TAG., yaml_BOOL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BOOL_TAG., yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., yaml_NULL_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_NULL_TAG., yaml_TIMESTAMP_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_TIMESTAMP_TAG.:
79 return true
80 }
81 return false
82 }
83
84 var yamlStyleFloatscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlStyleFloat. = regexpscip-go gomod github.com/golang/go/src go1.15 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.15 regexp/MustCompile().(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`)
85
86 func resolvescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolve().(tag string, in string) (rtag string, out interface{}) {
87 if !resolvableTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolvableTag().(tag) {
88 return tag, in
89 }
90
91 defer func() {
92 switch tag {
93 case "", rtag, yaml_STR_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_STR_TAG., yaml_BINARY_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BINARY_TAG.:
94 return
95 case yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG.:
96 if rtag == yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG. {
97 switch v := out.(type) {
98 case int64:
99 rtag = yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG.
100 out = float64(v)
101 return
102 case int:
103 rtag = yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG.
104 out = float64(v)
105 return
106 }
107 }
108 }
109 failfscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/failf().("cannot decode %s `%s` as a %s", shortTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/shortTag().(rtag), in, shortTagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/shortTag().(tag))
110 }()
111
112 // Any data is accepted as a !!str or !!binary.
113 // Otherwise, the prefix is enough of a hint about what it might be.
114 hint := byte('N')
115 if in != "" {
116 hint = resolveTablescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveTable.[in[0]]
117 }
118 if hint != 0 && tag != yaml_STR_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_STR_TAG. && tag != yaml_BINARY_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_BINARY_TAG. {
119 // Handle things we can lookup in a map.
120 if item, ok := resolveMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMap.[in]; ok {
121 return item.tagscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#tag., item.valuescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/resolveMapItem#value.
122 }
123
124 // Base 60 floats are a bad idea, were dropped in YAML 1.2, and
125 // are purposefully unsupported here. They're still quoted on
126 // the way out for compatibility with other parser, though.
127
128 switch hint {
129 case 'M':
130 // We've already checked the map above.
131
132 case '.':
133 // Not in the map, so maybe a normal float.
134 floatv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.15 strconv/ParseFloat().(in, 64)
135 if err == nil {
136 return yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., floatv
137 }
138
139 case 'D', 'S':
140 // Int, float, or timestamp.
141 // Only try values as a timestamp if the value is unquoted or there's an explicit
142 // !!timestamp tag.
143 if tag == "" || tag == yaml_TIMESTAMP_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_TIMESTAMP_TAG. {
144 t, ok := parseTimestampscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parseTimestamp().(in)
145 if ok {
146 return yaml_TIMESTAMP_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_TIMESTAMP_TAG., t
147 }
148 }
149
150 plain := stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Replacescip-go gomod github.com/golang/go/src go1.15 strings/Replace().(in, "_", "", -1)
151 intv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.15 strconv/ParseInt().(plain, 0, 64)
152 if err == nil {
153 if intv == int64(int(intv)) {
154 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., int(intv)
155 } else {
156 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., intv
157 }
158 }
159 uintv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.15 strconv/ParseUint().(plain, 0, 64)
160 if err == nil {
161 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., uintv
162 }
163 if yamlStyleFloatscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlStyleFloat..MatchStringscip-go gomod github.com/golang/go/src go1.15 regexp/Regexp#MatchString().(plain) {
164 floatv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.15 strconv/ParseFloat().(plain, 64)
165 if err == nil {
166 return yaml_FLOAT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_FLOAT_TAG., floatv
167 }
168 }
169 if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(plain, "0b") {
170 intv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.15 strconv/ParseInt().(plain[2:], 2, 64)
171 if err == nil {
172 if intv == int64(int(intv)) {
173 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., int(intv)
174 } else {
175 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., intv
176 }
177 }
178 uintv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.15 strconv/ParseUint().(plain[2:], 2, 64)
179 if err == nil {
180 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., uintv
181 }
182 } else if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(plain, "-0b") {
183 intv, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.15 strconv/ParseInt().("-" + plain[3:], 2, 64)
184 if err == nil {
•185 if intv == int64(int(intv)) {
186 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., int(intv)
187 } else {
188 return yaml_INT_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_INT_TAG., intv
189 }
190 }
191 }
192 default:
193 panic("resolveTable item not yet handled: " + string(rune(hint)) + " (with " + in + ")")
194 }
195 }
196 return yaml_STR_TAGscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yaml_STR_TAG., in
197 }
198
199 // encodeBase64 encodes s as base64 that is broken up into multiple lines
200 // as appropriate for the resulting length.
201 func encodeBase64scip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encodeBase64().(s string) string {
202 const lineLen = 70
203 encLen := base64scip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/StdEncoding..EncodedLenscip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/Encoding#EncodedLen().(len(s))
204 lines := encLen/lineLen + 1
205 buf := make([]byte, encLen*2+lines)
206 in := buf[0:encLen]
207 out := buf[encLen:]
208 base64scip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/StdEncoding..Encodescip-go gomod github.com/golang/go/src go1.15 `encoding/base64`/Encoding#Encode().(in, []byte(s))
209 k := 0
210 for i := 0; i < len(in); i += lineLen {
211 j := i + lineLen
212 if j > len(in) {
213 j = len(in)
214 }
215 k += copy(out[k:], in[i:j])
216 if lines > 1 {
217 out[k] = '\n'
218 k++
219 }
220 }
221 return string(out[:k])
222 }
223
224 // This is a subset of the formats allowed by the regular expression
225 // defined at http://yaml.org/type/timestamp.html.
226 var allowedTimestampFormatsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/allowedTimestampFormats. = []string{
227 "2006-1-2T15:4:5.999999999Z07:00", // RCF3339Nano with short date fields.
228 "2006-1-2t15:4:5.999999999Z07:00", // RFC3339Nano with short date fields and lower-case "t".
229 "2006-1-2 15:4:5.999999999", // space separated with no time zone
230 "2006-1-2", // date only
231 // Notable exception: time.Parse cannot handle: "2001-12-14 21:59:43.10 -5"
232 // from the set of examples.
233 }
234
235 // parseTimestamp parses s as a timestamp string and
236 // returns the timestamp and reports whether it succeeded.
237 // Timestamp formats are defined at http://yaml.org/type/timestamp.html
238 func parseTimestampscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parseTimestamp().(s string) (timescip-go gomod github.com/golang/go/src go1.15 time/.Timescip-go gomod github.com/golang/go/src go1.15 time/Time#, bool) {
239 // TODO write code to check all the formats supported by
240 // http://yaml.org/type/timestamp.html instead of using time.Parse.
241
242 // Quick check: all date formats start with YYYY-.
243 i := 0
244 for ; i < len(s); i++ {
245 if c := s[i]; c < '0' || c > '9' {
246 break
247 }
248 }
249 if i != 4 || i == len(s) || s[i] != '-' {
250 return timescip-go gomod github.com/golang/go/src go1.15 time/.Timescip-go gomod github.com/golang/go/src go1.15 time/Time#{}, false
251 }
252 for _, format := range allowedTimestampFormatsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/allowedTimestampFormats. {
253 if t, err := timescip-go gomod github.com/golang/go/src go1.15 time/.Parsescip-go gomod github.com/golang/go/src go1.15 time/Parse().(format, s); err == nil {
254 return t, true
255 }
256 }
257 return timescip-go gomod github.com/golang/go/src go1.15 time/.Timescip-go gomod github.com/golang/go/src go1.15 time/Time#{}, false
258 }