From: Russ Cox Date: Tue, 25 Nov 2008 17:23:13 +0000 (-0800) Subject: % x inserts spaces between hex bytes in string/*[]byte X-Git-Tag: weekly.2009-11-06~2608 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=afff0ff1b8442e9032266c392773a633604ff18c;p=gostls13.git % x inserts spaces between hex bytes in string/*[]byte R=r DELTA=7 (7 added, 0 deleted, 0 changed) OCL=19967 CL=19978 --- diff --git a/src/lib/fmt/fmt_test.go b/src/lib/fmt/fmt_test.go index ec1e9951bf..4b423c617f 100644 --- a/src/lib/fmt/fmt_test.go +++ b/src/lib/fmt/fmt_test.go @@ -45,6 +45,7 @@ var fmttests = []FmtTest{ // basic bytes FmtTest{ "%s", Bytes("abc"), "abc" }, FmtTest{ "%x", Bytes("abc"), "616263" }, + FmtTest{ "% x", Bytes("abc"), "61 62 63" }, FmtTest{ "%x", Bytes("xyz"), "78797a" }, FmtTest{ "%X", Bytes("xyz"), "78797A" }, FmtTest{ "%q", Bytes("abc"), `"abc"` }, diff --git a/src/lib/fmt/format.go b/src/lib/fmt/format.go index 64d6c9bc99..d1c20a513a 100644 --- a/src/lib/fmt/format.go +++ b/src/lib/fmt/format.go @@ -374,6 +374,9 @@ func (f *Fmt) s(s string) *Fmt { func (f *Fmt) sx(s string) *Fmt { t := ""; for i := 0; i < len(s); i++ { + if i > 0 && f.space { + t += " "; + } v := s[i]; t += string(ldigits[v>>4]); t += string(ldigits[v&0xF]);