| 1 | written by hand - just enough to compile rsc.io/sampler, rsc.io/quote |
|---|---|
| 2 | |
| 3 | -- .mod -- |
| 4 | module golang.org/x/text |
| 5 | -- .info -- |
| 6 | {"Version":"v0.0.0-20170915032832-14c0d48ead0c","Name":"v0.0.0-20170915032832-14c0d48ead0c","Short":"14c0d48ead0c","Time":"2017-09-15T03:28:32Z"} |
| 7 | -- go.mod -- |
| 8 | module golang.org/x/text |
| 9 | -- unused/unused.go -- |
| 10 | package unused |
| 11 | -- language/lang.go -- |
| 12 | // Copyright 2018 The Go Authors. All rights reserved. |
| 13 | // Use of this source code is governed by a BSD-style |
| 14 | // license that can be found in the LICENSE file. |
| 15 | |
| 16 | // This is a tiny version of golang.org/x/text. |
| 17 | |
| 18 | package language |
| 19 | |
| 20 | import "strings" |
| 21 | |
| 22 | type Tag string |
| 23 | |
| 24 | func Make(s string) Tag { return Tag(s) } |
| 25 | |
| 26 | func (t Tag) String() string { return string(t) } |
| 27 | |
| 28 | func NewMatcher(tags []Tag) Matcher { return &matcher{tags} } |
| 29 | |
| 30 | type Matcher interface { |
| 31 | Match(...Tag) (Tag, int, int) |
| 32 | } |
| 33 | |
| 34 | type matcher struct { |
| 35 | tags []Tag |
| 36 | } |
| 37 | |
| 38 | func (m *matcher) Match(prefs ...Tag) (Tag, int, int) { |
| 39 | for _, pref := range prefs { |
| 40 | for _, tag := range m.tags { |
| 41 | if tag == pref || strings.HasPrefix(string(pref), string(tag+"-")) || strings.HasPrefix(string(tag), string(pref+"-")) { |
| 42 | return tag, 0, 0 |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | return m.tags[0], 0, 0 |
| 47 | } |
| 48 |
Members