vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood
2017-09-30 15:27:27 +01:00
parent 911d121bb9
commit b017fcfe9a
3048 changed files with 537055 additions and 189679 deletions
+100
View File
@@ -0,0 +1,100 @@
// Copyright 2017 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 message implements formatted I/O for localized strings with functions
// analogous to the fmt's print functions. It is a drop-in replacement for fmt.
//
//
// Localized Formatting
//
// A format string can be localized by replacing any of the print functions of
// fmt with an equivalent call to a Printer.
//
// p := message.NewPrinter(language.English)
// p.Println(123456.78) // Prints 123,456.78
//
// p.Printf("%d ducks in a row", 4331) // Prints 4,331 ducks in a row
//
// p := message.NewPrinter(language.Dutch)
// p.Println("Hoogte: %f meter", 1244.9) // Prints Hoogte: 1.244,9 meter
//
// p := message.NewPrinter(language.Bengali)
// p.Println(123456.78) // Prints ১,২৩,৪৫৬.৭৮
//
// Printer currently supports numbers and specialized types for which packages
// exist in x/text. Other builtin types such as time.Time and slices are
// planned.
//
// Format strings largely have the same meaning as with fmt with the following
// notable exceptions:
// - flag # always resorts to fmt for printing
// - verb 'f', 'e', 'g', 'd' use localized formatting unless the '#' flag is
// specified.
//
// See package fmt for more options.
//
//
// Translation
//
// The format strings that are passed to Printf, Sprintf, Fprintf, or Errorf
// are used as keys to look up translations for the specified languages.
// More on how these need to be specified below.
//
// One can use arbitrary keys to distinguish between otherwise ambiguous
// strings:
// p := message.NewPrinter(language.English)
// p.Printf("archive(noun)") // Prints "archive"
// p.Printf("archive(verb)") // Prints "archive"
//
// p := message.NewPrinter(language.German)
// p.Printf("archive(noun)") // Prints "Archiv"
// p.Printf("archive(verb)") // Prints "archivieren"
//
// To retain the fallback functionality, use Key:
// p.Printf(message.Key("archive(noun)", "archive"))
// p.Printf(message.Key("archive(verb)", "archive"))
//
//
// Translation Pipeline
//
// Format strings that contain text need to be translated to support different
// locales. The first step is to extract strings that need to be translated.
//
// 1. Install gotext
// go get -u golang.org/x/text/cmd/gotext
// gotext -help
//
// 2. Mark strings in your source to be translated by using message.Printer,
// instead of the functions of the fmt package.
//
// 3. Extract the strings from your source
//
// gotext extract
//
// The output will be written to the textdata directory.
//
// 4. Send the files for translation
//
// It is planned to support multiple formats, but for now one will have to
// rewrite the JSON output to the desired format.
//
// 5. Inject translations into program
//
// 6. Repeat from 2
//
// Right now this has to be done programmatically with calls to Set or
// SetString. These functions as well as the methods defined in
// see also package golang.org/x/text/message/catalog can be used to implement
// either dynamic or static loading of messages.
//
//
// Plural and Gender Forms
//
// Translated messages can vary based on the plural and gender forms of
// substitution values. In general, it is up to the translators to provide
// alternative translations for such forms. See the packages in
// golang.org/x/text/feature and golang.org/x/text/message/catalog for more
// information.
//
package message
+42
View File
@@ -0,0 +1,42 @@
// Copyright 2017 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 message_test
import (
"net/http"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func Example_http() {
// languages supported by this service:
matcher := language.NewMatcher(message.DefaultCatalog.Languages())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
lang, _ := r.Cookie("lang")
accept := r.Header.Get("Accept-Language")
fallback := "en"
tag, _ := language.MatchStrings(matcher, lang.String(), accept, fallback)
p := message.NewPrinter(tag)
p.Fprintln(w, "User language is", tag)
})
}
func ExamplePrinter_numbers() {
for _, lang := range []string{"en", "de", "de-CH", "fr", "bn"} {
p := message.NewPrinter(language.Make(lang))
p.Printf("%-6s %g\n", lang, 123456.78)
}
// Output:
// en 123,456.78
// de 123.456,78
// de-CH 123’456.78
// fr 123 456,78
// bn ১,২৩,৪৫৬.৭৮
}
+6 -8
View File
@@ -475,10 +475,8 @@ var fmtTests = []struct {
{"%.4b", float32(1.0), "8388608p-23"},
{"%.4b", -1.0, "-4503599627370496p-52"},
// Test correct f.intbuf boundary checks.
// TODO: the following cases won't work because of rounding errors. We can
// fix this if we expose the internals of strconv.
// {"%.68f", 1.0, zeroFill("1.", 68, "")}, // TODO(bug): rounding error
// {"%.68f", -1.0, zeroFill("-1.", 68, "")}, // TODO(bug): rounding error
{"%.68f", 1.0, zeroFill("1.", 68, "")},
{"%.68f", -1.0, zeroFill("-1.", 68, "")},
// float infinites and NaNs
{"%f", posInf, "∞"},
{"%.1f", negInf, "-∞"},
@@ -565,8 +563,8 @@ var fmtTests = []struct {
// old test/fmt_test.go
{"%e", 1.0, "1.000000\u202f×\u202f10⁰⁰"},
{"%e", 1234.5678e3, "1.234570\u202f×\u202f10⁰⁶"},
{"%e", 1234.5678e-8, "1.234570\u202f×\u202f10⁻⁰⁵"},
{"%e", 1234.5678e3, "1.234568\u202f×\u202f10⁰⁶"},
{"%e", 1234.5678e-8, "1.234568\u202f×\u202f10⁻⁰⁵"},
{"%e", -7.0, "-7.000000\u202f×\u202f10⁰⁰"},
{"%e", -1e-9, "-1.000000\u202f×\u202f10⁻⁰⁹"},
{"%f", 1234.5678e3, "1,234,567.800000"},
@@ -580,8 +578,8 @@ var fmtTests = []struct {
{"%g", -1e-9, "-1\u202f×\u202f10⁻⁰⁹"},
{"%g", float32(-1e-9), "-1\u202f×\u202f10⁻⁰⁹"},
{"%E", 1.0, "1.000000\u202f×\u202f10⁰⁰"},
{"%E", 1234.5678e3, "1.234570\u202f×\u202f10⁰⁶"},
{"%E", 1234.5678e-8, "1.234570\u202f×\u202f10⁻⁰⁵"},
{"%E", 1234.5678e3, "1.234568\u202f×\u202f10⁰⁶"},
{"%E", 1234.5678e-8, "1.234568\u202f×\u202f10⁻⁰⁵"},
{"%E", -7.0, "-7.000000\u202f×\u202f10⁰⁰"},
{"%E", -1e-9, "-1.000000\u202f×\u202f10⁻⁰⁹"},
{"%G", 1234.5678e3, "1.2345678\u202f×\u202f10⁰⁶"},
+1 -9
View File
@@ -2,15 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package message implements formatted I/O for localized strings with functions
// analogous to the fmt's print functions.
//
// These are the important differences with fmt:
// - Output varies per locale.
// - The '#' flag is used to bypass localization.
//
// NOTE: Under construction. See https://golang.org/design/12750-localization
// and its corresponding proposal issue https://golang.org/issues/12750.
package message // import "golang.org/x/text/message"
import (
@@ -150,6 +141,7 @@ func lookupAndFormat(p *Printer, r Reference, a []interface{}) {
// Arg implements catmsg.Renderer.
func (p *printer) Arg(i int) interface{} { // TODO, also return "ok" bool
i--
if uint(i) < uint(len(p.args)) {
return p.args[i]
}
+25 -16
View File
@@ -11,6 +11,7 @@ import (
"reflect"
"unicode/utf8"
"golang.org/x/text/internal/format"
"golang.org/x/text/internal/number"
"golang.org/x/text/language"
"golang.org/x/text/message/catalog"
@@ -237,7 +238,7 @@ func (p *printer) fmtFloat(v float64, size int, verb rune) {
if p.fmt.sharp || p.fmt.sharpV {
p.fmt.fmt_float(v, size, verb, -1)
} else {
p.fmtVariableFloat(v, size, -1)
p.fmtVariableFloat(v, size)
}
case 'e', 'E':
if p.fmt.sharp || p.fmt.sharpV {
@@ -284,7 +285,7 @@ func (p *printer) initDecimal(minFrac, maxFrac int) {
f.MinIntegerDigits = 1
f.MaxIntegerDigits = 0
f.MinFractionDigits = uint8(minFrac)
f.MaxFractionDigits = uint8(maxFrac)
f.MaxFractionDigits = int16(maxFrac)
p.setFlags(f)
f.PadRune = 0
if p.fmt.widPresent {
@@ -308,8 +309,13 @@ func (p *printer) initDecimal(minFrac, maxFrac int) {
func (p *printer) initScientific(minFrac, maxFrac int) {
f := &p.toScientific
f.MinFractionDigits = uint8(minFrac)
f.MaxFractionDigits = uint8(maxFrac)
if maxFrac < 0 {
f.SetPrecision(maxFrac)
} else {
f.SetPrecision(maxFrac + 1)
f.MinFractionDigits = uint8(minFrac)
f.MaxFractionDigits = int16(maxFrac)
}
f.MinExponentDigits = 2
p.setFlags(f)
f.PadRune = 0
@@ -328,8 +334,6 @@ func (p *printer) initScientific(minFrac, maxFrac int) {
func (p *printer) fmtDecimalInt(v uint64, isSigned bool) {
var d number.Decimal
p.toDecimal.RoundingContext.Scale = 0
d.ConvertInt(&p.toDecimal.RoundingContext, isSigned, v)
f := &p.toDecimal
if p.fmt.precPresent {
@@ -344,6 +348,7 @@ func (p *printer) fmtDecimalInt(v uint64, isSigned bool) {
} else {
p.initDecimal(0, 0)
}
d.ConvertInt(p.toDecimal.RoundingContext, isSigned, v)
out := p.toDecimal.Format([]byte(nil), &d)
p.Buffer.Write(out)
@@ -354,22 +359,21 @@ func (p *printer) fmtDecimalFloat(v float64, size, prec int) {
if p.fmt.precPresent {
prec = p.fmt.prec
}
p.toDecimal.RoundingContext.Scale = int32(prec)
d.ConvertFloat(&p.toDecimal.RoundingContext, v, size)
p.initDecimal(prec, prec)
d.ConvertFloat(p.toDecimal.RoundingContext, v, size)
out := p.toDecimal.Format([]byte(nil), &d)
p.Buffer.Write(out)
}
func (p *printer) fmtVariableFloat(v float64, size, prec int) {
func (p *printer) fmtVariableFloat(v float64, size int) {
prec := -1
if p.fmt.precPresent {
prec = p.fmt.prec
}
var d number.Decimal
p.toScientific.RoundingContext.Precision = int32(prec)
d.ConvertFloat(&p.toScientific.RoundingContext, v, size)
p.initScientific(0, prec)
d.ConvertFloat(p.toScientific.RoundingContext, v, size)
// Copy logic of 'g' formatting from strconv. It is simplified a bit as
// we don't have to mind having prec > len(d.Digits).
@@ -407,10 +411,9 @@ func (p *printer) fmtScientific(v float64, size, prec int) {
if p.fmt.precPresent {
prec = p.fmt.prec
}
p.toScientific.RoundingContext.Precision = int32(prec)
d.ConvertFloat(&p.toScientific.RoundingContext, v, size)
p.initScientific(prec, prec)
rc := p.toScientific.RoundingContext
d.ConvertFloat(rc, v, size)
out := p.toScientific.Format([]byte(nil), &d)
p.Buffer.Write(out)
@@ -603,6 +606,12 @@ func (p *printer) handleMethods(verb rune) (handled bool) {
return
}
// Is it a Formatter?
if formatter, ok := p.arg.(format.Formatter); ok {
handled = true
defer p.catchPanic(p.arg, verb)
formatter.Format(p, verb)
return
}
if formatter, ok := p.arg.(fmt.Formatter); ok {
handled = true
defer p.catchPanic(p.arg, verb)
@@ -1038,7 +1047,7 @@ formatLoop:
p.fmt.plusV = p.fmt.plus
p.fmt.plus = false
}
p.printArg(p.Arg(p.argNum), rune(c))
p.printArg(p.Arg(p.argNum+1), rune(c))
p.argNum++
i++
continue formatLoop