1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Copyright 2019 Dominik Honnef. All rights reserved.
8 func parseStructTag(tag string) (map[string][]string, error) {
9 // FIXME(dh): detect missing closing quote
10 out := map[string][]string{}
13 // Skip leading space.
15 for i < len(tag) && tag[i] == ' ' {
23 // Scan to colon. A space, a quote or a control character is a syntax error.
24 // Strictly speaking, control chars include the range [0x7f, 0x9f], not just
25 // [0x00, 0x1f], but in practice, we ignore the multi-byte control characters
26 // as it is simpler to inspect the tag's bytes than the tag's runes.
28 for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f {
31 if i == 0 || i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' {
34 name := string(tag[:i])
37 // Scan quoted string to find value.
39 for i < len(tag) && tag[i] != '"' {
48 qvalue := string(tag[:i+1])
51 value, err := strconv.Unquote(qvalue)
55 out[name] = append(out[name], value)