]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: allow "% X" as well as "% x"
authorRob Pike <r@golang.org>
Mon, 29 Nov 2010 15:30:36 +0000 (07:30 -0800)
committerRob Pike <r@golang.org>
Mon, 29 Nov 2010 15:30:36 +0000 (07:30 -0800)
R=rsc, cw, PeterGo
CC=golang-dev
https://golang.org/cl/3319042

src/pkg/fmt/doc.go
src/pkg/fmt/fmt_test.go
src/pkg/fmt/format.go

index 06dc730089d5559be245ee3a9ee554d33173bbf7..a026a5e1973db0bad3218ddedd4dd2633fbacc2c 100644 (file)
@@ -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
index 2c09e0713b7290e027e69f413e2b4cbce9404454..fbc2536ee15a7a65791e2be3904c27a957f979d3 100644 (file)
@@ -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"`},
index 3ec1cf139432ec4fe2dc93a465ef86167cc9376f..010280bf851b8a133632aa1b0d4230282399c231 100644 (file)
@@ -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])