From 27196589fbd36f5f840e51b59bd6253d0f865db3 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 16 Dec 2017 11:25:18 -0800 Subject: Add FeedIcon API call and update dependencies --- vendor/golang.org/x/text/message/catalog/dict.go | 49 +++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'vendor/golang.org/x/text/message/catalog/dict.go') diff --git a/vendor/golang.org/x/text/message/catalog/dict.go b/vendor/golang.org/x/text/message/catalog/dict.go index 1810fab..a0eb818 100644 --- a/vendor/golang.org/x/text/message/catalog/dict.go +++ b/vendor/golang.org/x/text/message/catalog/dict.go @@ -33,7 +33,11 @@ func (d *dict) Lookup(key string) (data string, ok bool) { return d.s.lookup(d.tag, key) } -func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) error { +func (b *Builder) lookup(tag language.Tag, key string) (data string, ok bool) { + return b.index.lookup(tag, key) +} + +func (c *Builder) set(tag language.Tag, key string, s *store, msg ...Message) error { data, err := catmsg.Compile(tag, &dict{&c.macros, tag}, firstInSequence(msg)) s.mutex.Lock() @@ -45,6 +49,7 @@ func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) er if s.index == nil { s.index = map[language.Tag]msgMap{} } + c.matcher = nil s.index[tag] = m } @@ -52,6 +57,23 @@ func (c *Catalog) set(tag language.Tag, key string, s *store, msg ...Message) er return err } +func (c *Builder) Matcher() language.Matcher { + c.index.mutex.RLock() + m := c.matcher + c.index.mutex.RUnlock() + if m != nil { + return m + } + + c.index.mutex.Lock() + if c.matcher == nil { + c.matcher = language.NewMatcher(c.unlockedLanguages()) + } + m = c.matcher + c.index.mutex.Unlock() + return m +} + type store struct { mutex sync.RWMutex index map[language.Tag]msgMap @@ -76,15 +98,32 @@ func (s *store) lookup(tag language.Tag, key string) (data string, ok bool) { return "", false } -// Languages returns all languages for which the store contains variants. -func (s *store) languages() []language.Tag { +// Languages returns all languages for which the Catalog contains variants. +func (b *Builder) Languages() []language.Tag { + s := &b.index s.mutex.RLock() defer s.mutex.RUnlock() + return b.unlockedLanguages() +} + +func (b *Builder) unlockedLanguages() []language.Tag { + s := &b.index + if len(s.index) == 0 { + return nil + } tags := make([]language.Tag, 0, len(s.index)) + _, hasFallback := s.index[b.options.fallback] + offset := 0 + if hasFallback { + tags = append(tags, b.options.fallback) + offset = 1 + } for t := range s.index { - tags = append(tags, t) + if t != b.options.fallback { + tags = append(tags, t) + } } - internal.SortTags(tags) + internal.SortTags(tags[offset:]) return tags } -- cgit v1.2.3