diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-10-08 16:02:50 -0500 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-10-08 16:02:50 -0500 |
commit | baf7141d1dd0f99d561a2197a909c66dd389809d (patch) | |
tree | 92c176f713b0b28893344261b1e567db5e30ba79 /vendor/golang.org/x/text | |
parent | 696aebffe56853345d679d4d2b3051236423c6db (diff) |
Update dependencies
Diffstat (limited to 'vendor/golang.org/x/text')
-rw-r--r-- | vendor/golang.org/x/text/internal/gen/code.go | 1 | ||||
-rw-r--r-- | vendor/golang.org/x/text/internal/gen/gen.go | 92 | ||||
-rw-r--r-- | vendor/golang.org/x/text/internal/ucd/ucd.go | 19 | ||||
-rw-r--r-- | vendor/golang.org/x/text/transform/transform.go | 52 | ||||
-rw-r--r-- | vendor/golang.org/x/text/unicode/norm/normalize.go | 36 |
5 files changed, 170 insertions, 30 deletions
diff --git a/vendor/golang.org/x/text/internal/gen/code.go b/vendor/golang.org/x/text/internal/gen/code.go index ca917d2..2202c9f 100644 --- a/vendor/golang.org/x/text/internal/gen/code.go +++ b/vendor/golang.org/x/text/internal/gen/code.go @@ -187,6 +187,7 @@ func (w *CodeWriter) writeValue(v reflect.Value) { // WriteString writes a string literal. func (w *CodeWriter) WriteString(s string) { + s = strings.Replace(s, `\`, `\\`, -1) io.WriteString(w.Hash, s) // content hash w.Size += len(s) diff --git a/vendor/golang.org/x/text/internal/gen/gen.go b/vendor/golang.org/x/text/internal/gen/gen.go index dfaa278..9eb2987 100644 --- a/vendor/golang.org/x/text/internal/gen/gen.go +++ b/vendor/golang.org/x/text/internal/gen/gen.go @@ -22,6 +22,7 @@ import ( "bytes" "flag" "fmt" + "go/build" "go/format" "io" "io/ioutil" @@ -30,6 +31,7 @@ import ( "os" "path" "path/filepath" + "sync" "unicode" "golang.org/x/text/unicode/cldr" @@ -48,12 +50,6 @@ var ( cldrVersion = flag.String("cldr", getEnv("CLDR_VERSION", cldr.Version), "cldr version to use") - // Allow an environment variable to specify the local directory. - // go generate doesn't allow specifying arguments; this is a useful - // alternative to specifying a local mirror. - localDir = flag.String("local", - os.Getenv("UNICODE_DIR"), - "directory containing local data files; for debugging only.") ) func getEnv(name, def string) string { @@ -87,9 +83,12 @@ func CLDRVersion() string { return *cldrVersion } -// IsLocal reports whether the user specified a local directory. +// IsLocal reports whether data files are available locally. func IsLocal() bool { - return *localDir != "" + if _, err := os.Stat(localReadmeFile()); err != nil { + return false + } + return true } // OpenUCDFile opens the requested UCD file. The file is specified relative to @@ -124,29 +123,78 @@ func OpenIANAFile(path string) io.ReadCloser { return Open(*iana, "iana", path) } +var ( + dirMutex sync.Mutex + localDir string +) + +const permissions = 0755 + +func localReadmeFile() string { + p, err := build.Import("golang.org/x/text", "", build.FindOnly) + if err != nil { + log.Fatalf("Could not locate package: %v", err) + } + return filepath.Join(p.Dir, "DATA", "README") +} + +func getLocalDir() string { + dirMutex.Lock() + defer dirMutex.Unlock() + + readme := localReadmeFile() + dir := filepath.Dir(readme) + if _, err := os.Stat(readme); err != nil { + if err := os.MkdirAll(dir, permissions); err != nil { + log.Fatalf("Could not create directory: %v", err) + } + ioutil.WriteFile(readme, []byte(readmeTxt), permissions) + } + return dir +} + +const readmeTxt = `Generated by golang.org/x/text/internal/gen. DO NOT EDIT. + +This directory contains downloaded files used to generate the various tables +in the golang.org/x/text subrepo. + +Note that the language subtag repo (iana/assignments/language-subtag-registry) +and all other times in the iana subdirectory are not versioned and will need +to be periodically manually updated. The easiest way to do this is to remove +the entire iana directory. This is mostly of concern when updating the language +package. +` + // Open opens subdir/path if a local directory is specified and the file exists, // where subdir is a directory relative to the local root, or fetches it from // urlRoot/path otherwise. It will call log.Fatal if there are any errors. func Open(urlRoot, subdir, path string) io.ReadCloser { - if *localDir != "" { - path = filepath.FromSlash(path) - if f, err := os.Open(filepath.Join(*localDir, subdir, path)); err == nil { - return f - } - } - return get(urlRoot, path) + file := filepath.Join(getLocalDir(), subdir, filepath.FromSlash(path)) + return open(file, urlRoot, path) } func openUnicode(path string) io.ReadCloser { - if *localDir != "" { - path = filepath.FromSlash(path) - f, err := os.Open(filepath.Join(*localDir, path)) - if err != nil { - log.Fatal(err) - } + file := filepath.Join(getLocalDir(), filepath.FromSlash(path)) + return open(file, *url, path) +} + +// TODO: automatically periodically update non-versioned files. + +func open(file, urlRoot, path string) io.ReadCloser { + if f, err := os.Open(file); err == nil { return f } - return get(*url, path) + r := get(urlRoot, path) + defer r.Close() + b, err := ioutil.ReadAll(r) + if err != nil { + log.Fatalf("Could not download file: %v", err) + } + os.MkdirAll(filepath.Dir(file), permissions) + if err := ioutil.WriteFile(file, b, permissions); err != nil { + log.Fatalf("Could not create file: %v", err) + } + return ioutil.NopCloser(bytes.NewReader(b)) } func get(root, path string) io.ReadCloser { diff --git a/vendor/golang.org/x/text/internal/ucd/ucd.go b/vendor/golang.org/x/text/internal/ucd/ucd.go index 2b0d1a1..60b27d5 100644 --- a/vendor/golang.org/x/text/internal/ucd/ucd.go +++ b/vendor/golang.org/x/text/internal/ucd/ucd.go @@ -78,6 +78,14 @@ func Part(f func(p *Parser)) Option { } } +// The CommentHandler option passes comments that are on a line by itself to +// a given handler. +func CommentHandler(f func(s string)) Option { + return func(p *Parser) { + p.commentHandler = f + } +} + // A Parser parses Unicode Character Database (UCD) files. type Parser struct { scanner *bufio.Scanner @@ -92,7 +100,8 @@ type Parser struct { parsedRange bool rangeStart, rangeEnd rune - partHandler func(p *Parser) + partHandler func(p *Parser) + commentHandler func(s string) } func (p *Parser) setError(err error) { @@ -138,7 +147,13 @@ func (p *Parser) Next() bool { for p.scanner.Scan() { b := p.scanner.Bytes() - if len(b) == 0 || b[0] == '#' { + if len(b) == 0 { + continue + } + if b[0] == '#' { + if p.commentHandler != nil { + p.commentHandler(strings.TrimSpace(string(b[1:]))) + } continue } diff --git a/vendor/golang.org/x/text/transform/transform.go b/vendor/golang.org/x/text/transform/transform.go index 0c2f730..fe47b9b 100644 --- a/vendor/golang.org/x/text/transform/transform.go +++ b/vendor/golang.org/x/text/transform/transform.go @@ -24,6 +24,10 @@ var ( // complete the transformation. ErrShortSrc = errors.New("transform: short source buffer") + // ErrEndOfSpan means that the input and output (the transformed input) + // are not identical. + ErrEndOfSpan = errors.New("transform: input and output are not identical") + // errInconsistentByteCount means that Transform returned success (nil // error) but also returned nSrc inconsistent with the src argument. errInconsistentByteCount = errors.New("transform: inconsistent byte count returned") @@ -60,6 +64,41 @@ type Transformer interface { Reset() } +// SpanningTransformer extends the Transformer interface with a Span method +// that determines how much of the input already conforms to the Transformer. +type SpanningTransformer interface { + Transformer + + // Span returns a position in src such that transforming src[:n] results in + // identical output src[:n] for these bytes. It does not necessarily return + // the largest such n. The atEOF argument tells whether src represents the + // last bytes of the input. + // + // Callers should always account for the n bytes consumed before + // considering the error err. + // + // A nil error means that all input bytes are known to be identical to the + // output produced by the Transformer. A nil error can be be returned + // regardless of whether atEOF is true. If err is nil, then then n must + // equal len(src); the converse is not necessarily true. + // + // ErrEndOfSpan means that the Transformer output may differ from the + // input after n bytes. Note that n may be len(src), meaning that the output + // would contain additional bytes after otherwise identical output. + // ErrShortSrc means that src had insufficient data to determine whether the + // remaining bytes would change. Other than the error conditions listed + // here, implementations are free to report other errors that arise. + // + // Calling Span can modify the Transformer state as a side effect. In + // effect, it does the transformation just as calling Transform would, only + // without copying to a destination buffer and only up to a point it can + // determine the input and output bytes are the same. This is obviously more + // limited than calling Transform, but can be more efficient in terms of + // copying and allocating buffers. Calls to Span and Transform may be + // interleaved. + Span(src []byte, atEOF bool) (n int, err error) +} + // NopResetter can be embedded by implementations of Transformer to add a nop // Reset method. type NopResetter struct{} @@ -278,6 +317,10 @@ func (nop) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { return n, n, err } +func (nop) Span(src []byte, atEOF bool) (n int, err error) { + return len(src), nil +} + type discard struct{ NopResetter } func (discard) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { @@ -289,8 +332,8 @@ var ( // by consuming all bytes and writing nothing. Discard Transformer = discard{} - // Nop is a Transformer that copies src to dst. - Nop Transformer = nop{} + // Nop is a SpanningTransformer that copies src to dst. + Nop SpanningTransformer = nop{} ) // chain is a sequence of links. A chain with N Transformers has N+1 links and @@ -358,6 +401,8 @@ func (c *chain) Reset() { } } +// TODO: make chain use Span (is going to be fun to implement!) + // Transform applies the transformers of c in sequence. func (c *chain) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { // Set up src and dst in the chain. @@ -448,8 +493,7 @@ func (c *chain) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err erro return dstL.n, srcL.p, err } -// RemoveFunc returns a Transformer that removes from the input all runes r for -// which f(r) is true. Illegal bytes in the input are replaced by RuneError. +// Deprecated: use runes.Remove instead. func RemoveFunc(f func(r rune) bool) Transformer { return removeF(f) } diff --git a/vendor/golang.org/x/text/unicode/norm/normalize.go b/vendor/golang.org/x/text/unicode/norm/normalize.go index eb5596f..bba8ce9 100644 --- a/vendor/golang.org/x/text/unicode/norm/normalize.go +++ b/vendor/golang.org/x/text/unicode/norm/normalize.go @@ -8,7 +8,11 @@ // Package norm contains types and functions for normalizing Unicode strings. package norm // import "golang.org/x/text/unicode/norm" -import "unicode/utf8" +import ( + "unicode/utf8" + + "golang.org/x/text/transform" +) // A Form denotes a canonical representation of Unicode code points. // The Unicode-defined normalization and equivalence forms are: @@ -263,6 +267,34 @@ func (f Form) QuickSpan(b []byte) int { return n } +// Span implements transform.SpanningTransformer. It returns a boundary n such +// that b[0:n] == f(b[0:n]). It is not guaranteed to return the largest such n. +func (f Form) Span(b []byte, atEOF bool) (n int, err error) { + n, ok := formTable[f].quickSpan(inputBytes(b), 0, len(b), atEOF) + if n < len(b) { + if !ok { + err = transform.ErrEndOfSpan + } else { + err = transform.ErrShortSrc + } + } + return n, err +} + +// SpanString returns a boundary n such that s[0:n] == f(s[0:n]). +// It is not guaranteed to return the largest such n. +func (f Form) SpanString(s string, atEOF bool) (n int, err error) { + n, ok := formTable[f].quickSpan(inputString(s), 0, len(s), atEOF) + if n < len(s) { + if !ok { + err = transform.ErrEndOfSpan + } else { + err = transform.ErrShortSrc + } + } + return n, err +} + // quickSpan returns a boundary n such that src[0:n] == f(src[0:n]) and // whether any non-normalized parts were found. If atEOF is false, n will // not point past the last segment if this segment might be become @@ -321,7 +353,7 @@ func (f *formInfo) quickSpan(src input, i, end int, atEOF bool) (n int, ok bool) return lastSegStart, false } -// QuickSpanString returns a boundary n such that b[0:n] == f(s[0:n]). +// QuickSpanString returns a boundary n such that s[0:n] == f(s[0:n]). // It is not guaranteed to return the largest such n. func (f Form) QuickSpanString(s string) int { n, _ := formTable[f].quickSpan(inputString(s), 0, len(s), true) |