libgo: update to Go 1.11
[official-gcc.git] / libgo / go / encoding / json / tags.go
blobc38fd5102f6302deb1e10639dbe4552ee255837e
1 // Copyright 2011 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.
5 package json
7 import (
8 "strings"
11 // tagOptions is the string following a comma in a struct field's "json"
12 // tag, or the empty string. It does not include the leading comma.
13 type tagOptions string
15 // parseTag splits a struct field's json tag into its name and
16 // comma-separated options.
17 func parseTag(tag string) (string, tagOptions) {
18 if idx := strings.Index(tag, ","); idx != -1 {
19 return tag[:idx], tagOptions(tag[idx+1:])
21 return tag, tagOptions("")
24 // Contains reports whether a comma-separated list of options
25 // contains a particular substr flag. substr must be surrounded by a
26 // string boundary or commas.
27 func (o tagOptions) Contains(optionName string) bool {
28 if len(o) == 0 {
29 return false
31 s := string(o)
32 for s != "" {
33 var next string
34 i := strings.Index(s, ",")
35 if i >= 0 {
36 s, next = s[:i], s[i+1:]
38 if s == optionName {
39 return true
41 s = next
43 return false