// width
fmtTest{"%5s", "abc", " abc"},
+ fmtTest{"%2s", "\u263a", " \u263a"},
fmtTest{"%-5s", "abc", "abc "},
fmtTest{"%05s", "abc", "00abc"},
import (
"bytes"
"strconv"
+ "utf8"
)
const (
var padding []byte
var left, right int
if f.widPresent && f.wid != 0 {
- padding, left, right = f.computePadding(len(s))
+ padding, left, right = f.computePadding(utf8.RuneCountInString(s))
}
if left > 0 {
f.writePadding(left, padding)
For numeric values, the width and precision flags control
formatting; width sets the width of the field, precision the
number of places after the decimal, if appropriate. The
- format %6.2f prints 123.45.
+ format %6.2f prints 123.45. The width of a field is the number
+ of Unicode code points in the string. This differs from C's printf where
+ the field width is the number of bytes.
Other flags:
+ always print a sign for numeric values