summaryrefslogtreecommitdiff
path: root/src/fmt/print.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2019-01-29 22:24:36 -0500
committerRuss Cox <rsc@golang.org>2019-02-26 05:16:56 +0000
commitac51237affc016dd22f5b4f67dc8a2d09adf1fb2 (patch)
tree3a8ef2099ca6356ea1d69cab83f3755d8f09cdd2 /src/fmt/print.go
parente1a6d1fc08b2701ac9f67353cb52c51d52877669 (diff)
downloadgo-git-ac51237affc016dd22f5b4f67dc8a2d09adf1fb2.tar.gz
fmt: format 0b, 0o prefixes in %#b and %O
This CL modifies fmt's printer to implement %#b and %O to emit leading 0b and 0o prefixes on binary and octal. (%#o is already taken and emits "0377"; %O emits "0o377".) See golang.org/design/19308-number-literals for background. For #19308. For #12711. Vet update is #29986. Change-Id: I7c38a4484c48a03abe9f6d45c7d981c7c314f583 Reviewed-on: https://go-review.googlesource.com/c/160246 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/fmt/print.go')
-rw-r--r--src/fmt/print.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/fmt/print.go b/src/fmt/print.go
index 9976b8d263..121c7c59e4 100644
--- a/src/fmt/print.go
+++ b/src/fmt/print.go
@@ -363,7 +363,7 @@ func (p *pp) fmtBool(v bool, verb rune) {
func (p *pp) fmt0x64(v uint64, leading0x bool) {
sharp := p.fmt.sharp
p.fmt.sharp = leading0x
- p.fmt.fmtInteger(v, 16, unsigned, ldigits)
+ p.fmt.fmtInteger(v, 16, unsigned, 'v', ldigits)
p.fmt.sharp = sharp
}
@@ -374,18 +374,18 @@ func (p *pp) fmtInteger(v uint64, isSigned bool, verb rune) {
if p.fmt.sharpV && !isSigned {
p.fmt0x64(v, true)
} else {
- p.fmt.fmtInteger(v, 10, isSigned, ldigits)
+ p.fmt.fmtInteger(v, 10, isSigned, verb, ldigits)
}
case 'd':
- p.fmt.fmtInteger(v, 10, isSigned, ldigits)
+ p.fmt.fmtInteger(v, 10, isSigned, verb, ldigits)
case 'b':
- p.fmt.fmtInteger(v, 2, isSigned, ldigits)
- case 'o':
- p.fmt.fmtInteger(v, 8, isSigned, ldigits)
+ p.fmt.fmtInteger(v, 2, isSigned, verb, ldigits)
+ case 'o', 'O':
+ p.fmt.fmtInteger(v, 8, isSigned, verb, ldigits)
case 'x':
- p.fmt.fmtInteger(v, 16, isSigned, ldigits)
+ p.fmt.fmtInteger(v, 16, isSigned, verb, ldigits)
case 'X':
- p.fmt.fmtInteger(v, 16, isSigned, udigits)
+ p.fmt.fmtInteger(v, 16, isSigned, verb, udigits)
case 'c':
p.fmt.fmtC(v)
case 'q':
@@ -483,7 +483,7 @@ func (p *pp) fmtBytes(v []byte, verb rune, typeString string) {
if i > 0 {
p.buf.WriteByte(' ')
}
- p.fmt.fmtInteger(uint64(c), 10, unsigned, ldigits)
+ p.fmt.fmtInteger(uint64(c), 10, unsigned, verb, ldigits)
}
p.buf.WriteByte(']')
}