diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-01-18 19:04:36 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-18 19:04:36 +0000 |
commit | 4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch) | |
tree | f12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/strconv | |
parent | 225220d668dafb8262db7012bced688acbe63b33 (diff) | |
download | gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2 |
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019
gotools/:
* Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release.
(GOTOOLS_TEST_TIMEOUT): Increase to 600.
(check-runtime): Export LD_LIBRARY_PATH before computing GOARCH
and GOOS.
(check-vet): Copy golang.org/x/tools into check-vet-dir.
* Makefile.in: Regenerate.
gcc/testsuite/:
* go.go-torture/execute/names-1.go: Stop using debug/xcoff, which
is no longer externally visible.
From-SVN: r268084
Diffstat (limited to 'libgo/go/strconv')
-rw-r--r-- | libgo/go/strconv/atoi.go | 4 | ||||
-rw-r--r-- | libgo/go/strconv/doc.go | 4 | ||||
-rw-r--r-- | libgo/go/strconv/example_test.go | 56 | ||||
-rw-r--r-- | libgo/go/strconv/itoa.go | 12 | ||||
-rw-r--r-- | libgo/go/strconv/quote.go | 12 |
5 files changed, 71 insertions, 17 deletions
diff --git a/libgo/go/strconv/atoi.go b/libgo/go/strconv/atoi.go index bebed04..ff33d55 100644 --- a/libgo/go/strconv/atoi.go +++ b/libgo/go/strconv/atoi.go @@ -44,7 +44,7 @@ const intSize = 32 << (^uint(0) >> 63) // IntSize is the size in bits of an int or uint value. const IntSize = intSize -const maxUint64 = (1<<64 - 1) +const maxUint64 = 1<<64 - 1 // ParseUint is like ParseInt but for unsigned numbers. func ParseUint(s string, base int, bitSize int) (uint64, error) { @@ -198,7 +198,7 @@ func ParseInt(s string, base int, bitSize int) (i int64, err error) { return n, nil } -// Atoi returns the result of ParseInt(s, 10, 0) converted to type int. +// Atoi is equivalent to ParseInt(s, 10, 0), converted to type int. func Atoi(s string) (int, error) { const fnAtoi = "Atoi" diff --git a/libgo/go/strconv/doc.go b/libgo/go/strconv/doc.go index cba8984..8db725f 100644 --- a/libgo/go/strconv/doc.go +++ b/libgo/go/strconv/doc.go @@ -46,8 +46,8 @@ // The latter guarantees that the result is an ASCII string, by escaping // any non-ASCII Unicode with \u: // -// q := Quote("Hello, 世界") -// q := QuoteToASCII("Hello, 世界") +// q := strconv.Quote("Hello, 世界") +// q := strconv.QuoteToASCII("Hello, 世界") // // QuoteRune and QuoteRuneToASCII are similar but accept runes and // return quoted Go rune literals. diff --git a/libgo/go/strconv/example_test.go b/libgo/go/strconv/example_test.go index 5c2e8a9..2d1a2a9 100644 --- a/libgo/go/strconv/example_test.go +++ b/libgo/go/strconv/example_test.go @@ -167,6 +167,22 @@ func ExampleFormatUint() { // string, 2a } +func ExampleIsGraphic() { + shamrock := strconv.IsGraphic('☘') + fmt.Println(shamrock) + + a := strconv.IsGraphic('a') + fmt.Println(a) + + bel := strconv.IsGraphic('\007') + fmt.Println(bel) + + // Output: + // true + // true + // false +} + func ExampleIsPrint() { c := strconv.IsPrint('\u263a') fmt.Println(c) @@ -249,7 +265,7 @@ func ExampleParseUint() { } func ExampleQuote() { - s := strconv.Quote(`"Fran & Freddie's Diner ☺"`) + s := strconv.Quote(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal fmt.Println(s) // Output: @@ -272,14 +288,50 @@ func ExampleQuoteRuneToASCII() { // '\u263a' } +func ExampleQuoteRuneToGraphic() { + s := strconv.QuoteRuneToGraphic('☺') + fmt.Println(s) + + s = strconv.QuoteRuneToGraphic('\u263a') + fmt.Println(s) + + s = strconv.QuoteRuneToGraphic('\u000a') + fmt.Println(s) + + s = strconv.QuoteRuneToGraphic(' ') // tab character + fmt.Println(s) + + // Output: + // '☺' + // '☺' + // '\n' + // '\t' +} + func ExampleQuoteToASCII() { - s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`) + s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal fmt.Println(s) // Output: // "\"Fran & Freddie's Diner\t\u263a\"" } +func ExampleQuoteToGraphic() { + s := strconv.QuoteToGraphic("☺") + fmt.Println(s) + + s = strconv.QuoteToGraphic("This is a \u263a \u000a") // there is a tab character inside the string literal + fmt.Println(s) + + s = strconv.QuoteToGraphic(`" This is a ☺ \n "`) + fmt.Println(s) + + // Output: + // "☺" + // "This is a ☺\t\n" + // "\" This is a ☺ \\n \"" +} + func ExampleUnquote() { s, err := strconv.Unquote("You can't unquote a string without quotes") fmt.Printf("%q, %v\n", s, err) diff --git a/libgo/go/strconv/itoa.go b/libgo/go/strconv/itoa.go index 8afe7af..45e4192 100644 --- a/libgo/go/strconv/itoa.go +++ b/libgo/go/strconv/itoa.go @@ -30,7 +30,7 @@ func FormatInt(i int64, base int) string { return s } -// Itoa is shorthand for FormatInt(int64(i), 10). +// Itoa is equivalent to FormatInt(int64(i), 10). func Itoa(i int) string { return FormatInt(int64(i), 10) } @@ -152,10 +152,14 @@ func formatBits(dst []byte, u uint64, base int, neg, append_ bool) (d []byte, s } } else if isPowerOfTwo(base) { - // It is known that base is a power of two and - // 2 <= base <= len(digits). // Use shifts and masks instead of / and %. - shift := uint(bits.TrailingZeros(uint(base))) & 31 + // Base is a power of 2 and 2 <= base <= len(digits) where len(digits) is 36. + // The largest power of 2 below or equal to 36 is 32, which is 1 << 5; + // i.e., the largest possible shift count is 5. By &-ind that value with + // the constant 7 we tell the compiler that the shift count is always + // less than 8 which is smaller than any register width. This allows + // the compiler to generate better code for the shift operation. + shift := uint(bits.TrailingZeros(uint(base))) & 7 b := uint64(base) m := uint(base) - 1 // == 1<<shift - 1 for u >= b { diff --git a/libgo/go/strconv/quote.go b/libgo/go/strconv/quote.go index 9b7194a..6cd2f93 100644 --- a/libgo/go/strconv/quote.go +++ b/libgo/go/strconv/quote.go @@ -6,7 +6,10 @@ package strconv -import "unicode/utf8" +import ( + "internal/bytealg" + "unicode/utf8" +) const lowerhex = "0123456789abcdef" @@ -424,12 +427,7 @@ func Unquote(s string) (string, error) { // contains reports whether the string contains the byte c. func contains(s string, c byte) bool { - for i := 0; i < len(s); i++ { - if s[i] == c { - return true - } - } - return false + return bytealg.IndexByteString(s, c) != -1 } // bsearch16 returns the smallest i such that a[i] >= x. |