// TagGroups splits a TagSlice into Groups of TagSlices starting with a Split Tag
// and ending before the next Split Tag.
// A Split Tag is a tag with Code == splitCode, like (0, 'SECTION') for splitCode = 0.
429820
func TagGroups(tags TagSlice, splitCode int) []TagSlice {
	groups := make([]TagSlice, 0)

	group := make(TagSlice, 0)
	for _, tag := range tags {
		if tag.Code == splitCode {
			if len(group) > 0 {
				groups = append(groups, group)
				group = make(TagSlice, 0)
			}
			group = append(group, tag)
		} else if len(group) > 0 {
			group = append(group, tag)
		}
	}

	if len(group) > 0 && group[0].Code == splitCode {
		groups = append(groups, group)
	}

	return groups
}
310526
func Tags(tags map[string]string) SpanOption {
	return func(t *Tracer, s *spanImpl) {
		for k, v := range tags {
			s.Tags[k] = v
		}
	}
}
1165407
func (p *Pager) PageGroups() PagesGroup {
	if len(p.paginatedElements) == 0 {
		return paginatorEmptyPageGroups
	}

	if groups, ok := p.element().(PagesGroup); ok {
		return groups
	}

	return paginatorEmptyPageGroups
}
1372088
func CompareTags(a, b Tags) int {
	// Compare each key & value until a mismatch.
	for i := 0; i < len(a) && i < len(b); i++ {
		if cmp := bytes.Compare(a[i].Key, b[i].Key); cmp != 0 {
			return cmp
		}
		if cmp := bytes.Compare(a[i].Value, b[i].Value); cmp != 0 {
			return cmp
		}
	}

	// If all tags are equal up to this point then return shorter tagset.
	if len(a) < len(b) {
		return -1
	} else if len(a) > len(b) {
		return 1
	}

	// All tags are equal.
	return 0
}
377012
func (v *vcsCmd) tags(dir string) ([]string, error) {
	var tags []string
	for _, tc := range v.tagCmd {
		out, err := v.runOutput(dir, tc.cmd)
		if err != nil {
			return nil, err
		}
		re := regexp.MustCompile(`(?m-s)` + tc.pattern)
		for _, m := range re.FindAllStringSubmatch(string(out), -1) {
			tags = append(tags, m[1])
		}
	}
	return tags, nil
}
288245
func (s *WriteSegmentRequest) SetTags(v map[string]*string) *WriteSegmentRequest {
	s.Tags = v
	return s
}
439238
func (s *EntityFilter) SetTags(v []map[string]*string) *EntityFilter {
	s.Tags = v
	return s
}
1354260
func (b *builder) collapsedTags(ts []*Tag, count int, flatTags bool) []*Tag {
	ts = SortTags(ts, flatTags)
	if len(ts) <= count {
		return ts
	}

	tagGroups := make([][]*Tag, count)
	for i, t := range (ts)[:count] {
		tagGroups[i] = []*Tag{t}
	}
	for _, t := range (ts)[count:] {
		g, d := 0, tagDistance(t, tagGroups[0][0])
		for i := 1; i < count; i++ {
			if nd := tagDistance(t, tagGroups[i][0]); nd < d {
				g, d = i, nd
			}
		}
		tagGroups[g] = append(tagGroups[g], t)
	}

	var nts []*Tag
	for _, g := range tagGroups {
		l, w, c := b.tagGroupLabel(g)
		nts = append(nts, &Tag{
			Name: l,
			Flat: w,
			Cum:  c,
		})
	}
	return SortTags(nts, flatTags)
}
1371912
func SetTags(tags map[string]string) {
	singltonLock.RLock()
	defer singltonLock.RUnlock()

	blog.SetTags(tags)
}
1154995
func SortTags(tags []*ec2.Tag) {
	keys := make([]string, len(tags))
	for i := range tags {
		if tags[i] != nil {
			keys[i] = aws.StringValue(tags[i].Key)
		}
	}
	sort.SliceStable(tags, func(i, j int) bool { return keys[i] < keys[j] })
}
387330
func ReadTagged(text, sep string) TupleSlice {
	t := TupleSlice{}
	for _, sent := range strings.Split(text, "\n") {
		tokens := []string{}
		tags := []string{}
		for _, token := range strings.Split(sent, " ") {
			parts := strings.Split(token, sep)
			tokens = append(tokens, parts[0])
			tags = append(tags, parts[1])
		}
		t = append(t, [][]string{tokens, tags})
	}
	return t
}
946088
func mergeTags(metricTags, outerTags map[string]string) map[string]string {
	tags := make(map[string]string)
	for k, v := range outerTags {
		tags[k] = v
	}
	for k, v := range metricTags {
		tags[k] = v
	}

	return tags
}
984505
func ParseTags(m string) Tags {
	maxNum := 5
	tags := make(Tags)
	var r rune
	var i_s int = 0

	for i := 0; i < len(m); i += i_s {
		r, i_s = utf8.DecodeRuneInString(m[i:])
		if r == '#' {
			var j_s int
			var v rune
			var j int
			for j = i; j < len(m); j += j_s {
				v, j_s = utf8.DecodeRuneInString(m[j:])
				if isTagBreak(v) {
					break
				}
			}
			tag := Tag(m[i:j])
			//fmt.Printf("i: %d, j: %d, tag: %s\n", i, j, tag)
			if len(tags) >= maxNum {
				break
			}
			tags[tag] = struct{}{}
			i = j
			i_s = 0
		}
	}
	return tags
}
1217590
func (s *StackSet) SetTags(v []*Tag) *StackSet {
	s.Tags = v
	return s
}
312678
func (s *Branch) SetTags(v map[string]*string) *Branch {
	s.Tags = v
	return s
}
1221149
func (g *Group) Tag(items map[string]string) *Statement {
	// notest
	// don't think this can ever be used in valid code?
	s := Tag(items)
	g.items = append(g.items, s)
	return s
}
389406
func (slice TagSlice) AppDataTags() map[string][]*Tag {
	appData := make(map[string][]*Tag)
	appTags := make([]*Tag, 0)

	for _, tag := range slice {
		if tag.Code == appDataMarker {
			if tag.Value.ToString() == "}" {
				appTags = append(appTags, tag)
				appData[appTags[0].Value.ToString()] = appTags
				appTags = appTags[:0]
			} else {
				appTags = appTags[:0]
				appTags = append(appTags, tag)
			}
		} else {
			if len(appTags) > 0 {
				appTags = append(appTags, tag)
			}
		}
	}

	return appData
}