File: tag.go

package info (click to toggle)
golang-gopkg-vmihailenco-msgpack.v2 3.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 236 kB
  • sloc: makefile: 7
file content (42 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package msgpack

import (
	"strings"
)

type tagOptions string

func (o tagOptions) Get(name string) (string, bool) {
	s := string(o)
	for len(s) > 0 {
		var next string
		idx := strings.IndexByte(s, ',')
		if idx >= 0 {
			s, next = s[:idx], s[idx+1:]
		}
		if strings.HasPrefix(s, name) {
			return s[len(name):], true
		}
		s = next
	}
	return "", false
}

func (o tagOptions) Contains(name string) bool {
	_, ok := o.Get(name)
	return ok
}

func parseTag(tag string) (string, tagOptions) {
	if idx := strings.IndexByte(tag, ','); idx != -1 {
		name := tag[:idx]
		if strings.IndexByte(name, ':') == -1 {
			return name, tagOptions(tag[idx+1:])
		}
	}

	if strings.IndexByte(tag, ':') == -1 {
		return tag, ""
	}
	return "", tagOptions(tag)
}