diff options
author | Corey Hulen <corey@hulen.com> | 2017-03-24 23:31:34 -0700 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-03-25 03:31:34 -0300 |
commit | 54d3d47daf9190275bbdaf8703b84969a4593451 (patch) | |
tree | 05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/golang.org/x/text/collate/tools/colcmp/col.go | |
parent | 7460302dec7796e01c98264e84bece8169cb6ed9 (diff) | |
download | chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2 chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip |
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes
* Removing the old fsnotify lib
* updating some missing libs
Diffstat (limited to 'vendor/golang.org/x/text/collate/tools/colcmp/col.go')
-rw-r--r-- | vendor/golang.org/x/text/collate/tools/colcmp/col.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/golang.org/x/text/collate/tools/colcmp/col.go b/vendor/golang.org/x/text/collate/tools/colcmp/col.go new file mode 100644 index 000000000..dc22d2eef --- /dev/null +++ b/vendor/golang.org/x/text/collate/tools/colcmp/col.go @@ -0,0 +1,97 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "log" + "unicode/utf16" + + "golang.org/x/text/collate" + "golang.org/x/text/language" +) + +// Input holds an input string in both UTF-8 and UTF-16 format. +type Input struct { + index int // used for restoring to original random order + UTF8 []byte + UTF16 []uint16 + key []byte // used for sorting +} + +func (i Input) String() string { + return string(i.UTF8) +} + +func makeInput(s8 []byte, s16 []uint16) Input { + return Input{UTF8: s8, UTF16: s16} +} + +func makeInputString(s string) Input { + return Input{ + UTF8: []byte(s), + UTF16: utf16.Encode([]rune(s)), + } +} + +// Collator is an interface for architecture-specific implementations of collation. +type Collator interface { + // Key generates a sort key for the given input. Implemenations + // may return nil if a collator does not support sort keys. + Key(s Input) []byte + + // Compare returns -1 if a < b, 1 if a > b and 0 if a == b. + Compare(a, b Input) int +} + +// CollatorFactory creates a Collator for a given language tag. +type CollatorFactory struct { + name string + makeFn func(tag string) (Collator, error) + description string +} + +var collators = []CollatorFactory{} + +// AddFactory registers f as a factory for an implementation of Collator. +func AddFactory(f CollatorFactory) { + collators = append(collators, f) +} + +func getCollator(name, locale string) Collator { + for _, f := range collators { + if f.name == name { + col, err := f.makeFn(locale) + if err != nil { + log.Fatal(err) + } + return col + } + } + log.Fatalf("collator of type %q not found", name) + return nil +} + +// goCollator is an implemention of Collator using go's own collator. +type goCollator struct { + c *collate.Collator + buf collate.Buffer +} + +func init() { + AddFactory(CollatorFactory{"go", newGoCollator, "Go's native collator implementation."}) +} + +func newGoCollator(loc string) (Collator, error) { + c := &goCollator{c: collate.New(language.Make(loc))} + return c, nil +} + +func (c *goCollator) Key(b Input) []byte { + return c.c.Key(&c.buf, b.UTF8) +} + +func (c *goCollator) Compare(a, b Input) int { + return c.c.Compare(a.UTF8, b.UTF8) +} |