%F synonym for %f
%g %e for large exponents, %f otherwise
%G %E for large exponents, %F otherwise
- String and slice of bytes:
+ String and slice of bytes (treated equivalently with these verbs):
%s the uninterpreted bytes of the string or slice
%q a double-quoted string safely escaped with Go syntax
%x base 16, lower-case, two characters per byte
of strings, and %6.2f will control formatting for each element
of a floating-point array.
+ However, when printing a byte slice with a string-like verb
+ (%s %q %x %X), it is treated identically to a string, as a single item.
+
To avoid recursion in cases such as
type X string
func (x X) String() string { return Sprintf("<%s>", x) }
{"%q", []string{"a", "b"}, `["a" "b"]`},
{"% 02x", []byte{1}, "01"},
{"% 02x", []byte{1, 2, 3}, "01 02 03"},
- // Special care for empty slices.
+ // Padding with byte slices.
{"%x", []byte{}, ""},
- {"%02x", []byte{}, ""},
- {"% 02x", []byte{}, ""},
+ {"%02x", []byte{}, "00"},
+ {"% 02x", []byte{}, "00"},
+ {"%08x", []byte{0xab}, "000000ab"},
+ {"% 08x", []byte{0xab}, "000000ab"},
+ {"%08x", []byte{0xab, 0xcd}, "0000abcd"},
+ {"% 08x", []byte{0xab, 0xcd}, "000ab cd"},
+ {"%8x", []byte{0xab}, " ab"},
+ {"% 8x", []byte{0xab}, " ab"},
+ {"%8x", []byte{0xab, 0xcd}, " abcd"},
+ {"% 8x", []byte{0xab, 0xcd}, " ab cd"},
+ // Same for strings
+ {"%x", "", ""},
+ {"%02x", "", "00"},
+ {"% 02x", "", "00"},
+ {"%08x", "\xab", "000000ab"},
+ {"% 08x", "\xab", "000000ab"},
+ {"%08x", "\xab\xcd", "0000abcd"},
+ {"% 08x", "\xab\xcd", "000ab cd"},
+ {"%8x", "\xab", " ab"},
+ {"% 8x", "\xab", " ab"},
+ {"%8x", "\xab\xcd", " abcd"},
+ {"% 8x", "\xab\xcd", " ab cd"},
// renamings
{"%v", renamedBool(true), "true"},