diff options
author | Rob Pike <r@golang.org> | 2010-11-29 07:30:36 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2010-11-29 07:30:36 -0800 |
commit | d90d0ede3f14c0f3984ddec091c0119bdcf2dae3 (patch) | |
tree | 97b02861c7006fa0d83c899a9105652540f78767 | |
parent | abb0c0967cb48a291d4a640b2eac684ec5951c7b (diff) | |
download | go-d90d0ede3f14c0f3984ddec091c0119bdcf2dae3.tar.gz go-d90d0ede3f14c0f3984ddec091c0119bdcf2dae3.zip |
fmt: allow "% X" as well as "% x"
R=rsc, cw, PeterGo
CC=golang-dev
https://golang.org/cl/3319042
-rw-r--r-- | src/pkg/fmt/doc.go | 2 | ||||
-rw-r--r-- | src/pkg/fmt/fmt_test.go | 3 | ||||
-rw-r--r-- | src/pkg/fmt/format.go | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/src/pkg/fmt/doc.go b/src/pkg/fmt/doc.go index 06dc730089..a026a5e197 100644 --- a/src/pkg/fmt/doc.go +++ b/src/pkg/fmt/doc.go @@ -58,7 +58,7 @@ 0X for hex (%#X); suppress 0x for %p (%#p); print a raw (backquoted) string if possible for %q (%#q) ' ' (space) leave a space for elided sign in numbers (% d); - put spaces between bytes printing strings or slices in hex (% x) + put spaces between bytes printing strings or slices in hex (% x, % X) 0 pad with leading zeros rather than spaces For each Printf-like function, there is also a Print function diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index 2c09e0713b..fbc2536ee1 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -121,7 +121,8 @@ var fmttests = []fmtTest{ // basic bytes {"%s", []byte("abc"), "abc"}, {"%x", []byte("abc"), "616263"}, - {"% x", []byte("abc"), "61 62 63"}, + {"% x", []byte("abc\xff"), "61 62 63 ff"}, + {"% X", []byte("abc\xff"), "61 62 63 FF"}, {"%x", []byte("xyz"), "78797a"}, {"%X", []byte("xyz"), "78797A"}, {"%q", []byte("abc"), `"abc"`}, diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go index 3ec1cf1394..010280bf85 100644 --- a/src/pkg/fmt/format.go +++ b/src/pkg/fmt/format.go @@ -255,6 +255,9 @@ func (f *fmt) fmt_sx(s string) { func (f *fmt) fmt_sX(s string) { t := "" for i := 0; i < len(s); i++ { + if i > 0 && f.space { + t += " " + } v := s[i] t += string(udigits[v>>4]) t += string(udigits[v&0xF]) |