diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/math/big/intconv.go | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/math/big/intconv.go')
-rw-r--r-- | libgo/go/math/big/intconv.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/libgo/go/math/big/intconv.go b/libgo/go/math/big/intconv.go index 6cca827..0567284 100644 --- a/libgo/go/math/big/intconv.go +++ b/libgo/go/math/big/intconv.go @@ -16,7 +16,8 @@ import ( // Base must be between 2 and 62, inclusive. The result uses the // lower-case letters 'a' to 'z' for digit values 10 to 35, and // the upper-case letters 'A' to 'Z' for digit values 36 to 61. -// No prefix (such as "0x") is added to the string. +// No prefix (such as "0x") is added to the string. If x is a nil +// pointer it returns "<nil>". func (x *Int) Text(base int) string { if x == nil { return "<nil>" @@ -33,6 +34,8 @@ func (x *Int) Append(buf []byte, base int) []byte { return append(buf, x.abs.itoa(x.neg, base)...) } +// String returns the decimal representation of x as generated by +// x.Text(10). func (x *Int) String() string { return x.Text(10) } @@ -50,8 +53,9 @@ func writeMultiple(s fmt.State, text string, count int) { var _ fmt.Formatter = intOne // *Int must implement fmt.Formatter // Format implements fmt.Formatter. It accepts the formats -// 'b' (binary), 'o' (octal), 'd' (decimal), 'x' (lowercase -// hexadecimal), and 'X' (uppercase hexadecimal). +// 'b' (binary), 'o' (octal with 0 prefix), 'O' (octal with 0o prefix), +// 'd' (decimal), 'x' (lowercase hexadecimal), and +// 'X' (uppercase hexadecimal). // Also supported are the full suite of package fmt's format // flags for integral types, including '+' and ' ' for sign // control, '#' for leading zero in octal and for hexadecimal, @@ -66,7 +70,7 @@ func (x *Int) Format(s fmt.State, ch rune) { switch ch { case 'b': base = 2 - case 'o': + case 'o', 'O': base = 8 case 'd', 's', 'v': base = 10 @@ -98,6 +102,8 @@ func (x *Int) Format(s fmt.State, ch rune) { prefix := "" if s.Flag('#') { switch ch { + case 'b': // binary + prefix = "0b" case 'o': // octal prefix = "0" case 'x': // hexadecimal @@ -106,6 +112,9 @@ func (x *Int) Format(s fmt.State, ch rune) { prefix = "0X" } } + if ch == 'O' { + prefix = "0o" + } digits := x.abs.utoa(base) if ch == 'X' { @@ -166,8 +175,9 @@ func (x *Int) Format(s fmt.State, ch rune) { // // The base argument must be 0 or a value from 2 through MaxBase. If the base // is 0, the string prefix determines the actual conversion base. A prefix of -// ``0x'' or ``0X'' selects base 16; the ``0'' prefix selects base 8, and a -// ``0b'' or ``0B'' prefix selects base 2. Otherwise the selected base is 10. +// ``0b'' or ``0B'' selects base 2; a ``0'', ``0o'', or ``0O'' prefix selects +// base 8, and a ``0x'' or ``0X'' prefix selects base 16. Otherwise the selected +// base is 10. // func (z *Int) scan(r io.ByteScanner, base int) (*Int, int, error) { // determine sign |