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. 4 5package json 6 7import ( 8 "strings" 9) 10 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. 13type tagOptions string 14 15// parseTag splits a struct field's json tag into its name and 16// comma-separated options. 17func parseTag(tag string) (string, tagOptions) { 18 tag, opt, _ := strings.Cut(tag, ",") 19 return tag, tagOptions(opt) 20} 21 22// Contains reports whether a comma-separated list of options 23// contains a particular substr flag. substr must be surrounded by a 24// string boundary or commas. 25func (o tagOptions) Contains(optionName string) bool { 26 if len(o) == 0 { 27 return false 28 } 29 s := string(o) 30 for s != "" { 31 var name string 32 name, s, _ = strings.Cut(s, ",") 33 if name == optionName { 34 return true 35 } 36 } 37 return false 38} 39