func (t *tagIndex) keys(f func(key string)) {
	for i, s := range *t {
		for ; s != ""; s = s[i+2:] {
			f(s[:i+2])
		}
	}
}
keys calls f for each tag.
package display
import (
	"fmt"
	"sort"
	"strings"
	"golang.org/x/text/language"
)
type namer interface {
	name(idx int) string
}
func nameLanguage(n namer, x interface{}) string {
	t, _ := language.All.Compose(x)
	i, _, _ := langTagSet.index(t.Raw())
	return n.name(i)
}
func nameScript(n namer, x interface{}) string {
	t, _ := language.DeprecatedScript.Compose(x)
	_, s, _ := t.Raw()
	return n.name(scriptIndex.index(s.String()))
}
func nameRegion(n namer, x interface{}) string {
	t, _ := language.DeprecatedRegion.Compose(x)
	_, _, r := t.Raw()
	return n.name(regionIndex.index(r.String()))
}
func nameTag(langN, scrN, regN namer, x interface{}) string {
	t, ok := x.(language.Tag)
	if !ok {
		return ""
	}
	const form = language.All &^ language.SuppressScript
	if c, err := form.Canonicalize(t); err == nil {
		t = c
	}
	i, scr, reg := langTagSet.index(t.Raw())
	if i == -1 {
		return ""
	}
	str := langN.name(i)
	if hasS, hasR := (scr != language.Script{}), (reg != language.Region{}); hasS || hasR {
		ss, sr := "", ""
		if hasS {
			ss = scrN.name(scriptIndex.index(scr.String()))
		}
		if hasR {
			sr = regN.name(regionIndex.index(reg.String()))
		}
		if ss != "" && sr != "" {
			return fmt.Sprintf("%s (%s, %s)", str, ss, sr)
		}
		if ss != "" || sr != "" {
			return fmt.Sprintf("%s (%s%s)", str, ss, sr)
		}
	}
	return str
}
type header struct {
	data  string
	index []uint16
}
func (h *header) name(i int) string {
	if 0 <= i && i < len(h.index)-1 {
		return h.data[h.index[i]:h.index[i+1]]
	}
	return ""
}
type tagSet struct {
	single tagIndex
	long   []string
}
var (
	langTagSet = tagSet{
		single: langIndex,
		long:   langTagsLong,
	}
	selfTagSet = tagSet{
		single: selfIndex,
		long:   selfTagsLong,
	}
	zzzz = language.MustParseScript("Zzzz")
	zz   = language.MustParseRegion("ZZ")
)
func (ts *tagSet) index(base language.Base, scr language.Script, reg language.Region) (int, language.Script, language.Region) {
	lang := base.String()
	index := -1
	if (scr != language.Script{} || reg != language.Region{}) {
		if scr == zzzz {
			scr = language.Script{}
		}
		if reg == zz {
			reg = language.Region{}
		}
		i := sort.SearchStrings(ts.long, lang)
		scrStr, regStr := scr.String(), reg.String()
		for ; i < len(ts.long) && strings.HasPrefix(ts.long[i], lang); i++ {
			if s := ts.long[i][len(lang)+1:]; s == scrStr {
				scr = language.Script{}
				index = i + ts.single.len()
				break
			} else if s == regStr {
				reg = language.Region{}
				index = i + ts.single.len()
				break
			}
		}
	}
	if index == -1 {
		index = ts.single.index(lang)
	}
	return index, scr, reg
}
func (ts *tagSet) Tags() []language.Tag {
	tags := make([]language.Tag, 0, ts.single.len()+len(ts.long))
	ts.single.keys(func(s string) {
		tags = append(tags, language.Raw.MustParse(s))
	})
	for _, s := range ts.long {
		tags = append(tags, language.Raw.MustParse(s))
	}
	return tags
}
func supportedScripts() []language.Script {
	scr := make([]language.Script, 0, scriptIndex.len())
	scriptIndex.keys(func(s string) {
		scr = append(scr, language.MustParseScript(s))
	})
	return scr
}
func supportedRegions() []language.Region {
	reg := make([]language.Region, 0, regionIndex.len())
	regionIndex.keys(func(s string) {
		reg = append(reg, language.MustParseRegion(s))
	})
	return reg
}
type tagIndex [3]string
func (t *tagIndex) index(s string) int {
	sz := len(s)
	if sz < 2 || 4 < sz {
		return -1
	}
	a := t[sz-2]
	index := sort.Search(len(a)/sz, func(i int) bool {
		p := i * sz
		return a[p:p+sz] >= s
	})
	p := index * sz
	if end := p + sz; end > len(a) || a[p:end] != s {
		return -1
	}
	for i := 0; i < sz-2; i++ {
		index += len(t[i]) / (i + 2)
	}
	return index
}
func (t *tagIndex) len() (n int) {
	for i, s := range t {
		n += len(s) / (i + 2)
	}
	return n
}