aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json')
-rw-r--r--src/encoding/json/tags.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/encoding/json/tags.go b/src/encoding/json/tags.go
index c38fd5102f..b490328f4c 100644
--- a/src/encoding/json/tags.go
+++ b/src/encoding/json/tags.go
@@ -15,10 +15,8 @@ type tagOptions string
// parseTag splits a struct field's json tag into its name and
// comma-separated options.
func parseTag(tag string) (string, tagOptions) {
- if idx := strings.Index(tag, ","); idx != -1 {
- return tag[:idx], tagOptions(tag[idx+1:])
- }
- return tag, tagOptions("")
+ tag, opt, _ := strings.Cut(tag, ",")
+ return tag, tagOptions(opt)
}
// Contains reports whether a comma-separated list of options
@@ -30,15 +28,11 @@ func (o tagOptions) Contains(optionName string) bool {
}
s := string(o)
for s != "" {
- var next string
- i := strings.Index(s, ",")
- if i >= 0 {
- s, next = s[:i], s[i+1:]
- }
- if s == optionName {
+ var name string
+ name, s, _ = strings.Cut(s, ",")
+ if name == optionName {
return true
}
- s = next
}
return false
}