diff options
| author | Russ Cox <rsc@golang.org> | 2019-01-29 22:24:36 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2019-02-26 05:16:56 +0000 |
| commit | ac51237affc016dd22f5b4f67dc8a2d09adf1fb2 (patch) | |
| tree | 3a8ef2099ca6356ea1d69cab83f3755d8f09cdd2 /src/fmt/doc.go | |
| parent | e1a6d1fc08b2701ac9f67353cb52c51d52877669 (diff) | |
| download | go-ac51237affc016dd22f5b4f67dc8a2d09adf1fb2.tar.xz | |
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/doc.go')
| -rw-r--r-- | src/fmt/doc.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/fmt/doc.go b/src/fmt/doc.go index c349f8e321..e0edff456c 100644 --- a/src/fmt/doc.go +++ b/src/fmt/doc.go @@ -26,6 +26,7 @@ %c the character represented by the corresponding Unicode code point %d base 10 %o base 8 + %O base 8 with 0o prefix %q a single-quoted character literal safely escaped with Go syntax. %x base 16, with lower-case letters for a-f %X base 16, with upper-case letters for A-F @@ -113,8 +114,8 @@ + always print a sign for numeric values; guarantee ASCII-only output for %q (%+q) - pad with spaces on the right rather than the left (left-justify the field) - # alternate format: add leading 0 for octal (%#o), 0x for hex (%#x); - 0X for hex (%#X); suppress 0x for %p (%#p); + # alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), + 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); for %q, print a raw (backquoted) string if strconv.CanBackquote returns true; always print a decimal point for %e, %E, %f, %F, %g and %G; |
