Debian Codegraph @

tags.go

raw symbols SCIP
1 // Copyright 2016 Richard Gibson. All rights reserved.
2 // Copyright 2011 The Go Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package canonicaljson
7
8 import (
9 "strings"
10 )
11
12 // tagOptions is the string following a comma in a struct field's "json"
13 // tag, or the empty string. It does not include the leading comma.
14 type tagOptions string
15
16 // parseTag splits a struct field's json tag into its name and
17 // comma-separated options.
18 func parseTag(tag string) (string, tagOptions) {
19 if idx := strings.Index(tag, ","); idx != -1 {
20 return tag[:idx], tagOptions(tag[idx+1:])
21 }
22 return tag, tagOptions("")
23 }
24
25 // Contains reports whether a comma-separated list of options
26 // contains a particular substr flag. substr must be surrounded by a
27 // string boundary or commas.
28 func (o tagOptions) Contains(optionName string) bool {
29 if len(o) == 0 {
30 return false
31 }
32 s := string(o)
33 for s != "" {
34 var next string
35 i := strings.Index(s, ",")
36 if i >= 0 {
37 s, next = s[:i], s[i+1:]
38 }
39 if s == optionName {
40 return true
41 }
42 s = next
43 }
44 return false
45 }