summaryrefslogtreecommitdiff
path: root/src/pkg/fmt/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/fmt/format.go')
-rw-r--r--src/pkg/fmt/format.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go
index 1567609cf..137c355bb 100644
--- a/src/pkg/fmt/format.go
+++ b/src/pkg/fmt/format.go
@@ -43,13 +43,14 @@ type fmt struct {
wid int
prec int
// flags
- widPresent bool
- precPresent bool
- minus bool
- plus bool
- sharp bool
- space bool
- zero bool
+ widPresent bool
+ precPresent bool
+ minus bool
+ plus bool
+ sharp bool
+ space bool
+ zero bool
+ preserveFlags bool // don't clear flags after this print; used to carry over in complex prints
}
func (f *fmt) clearflags() {
@@ -119,7 +120,9 @@ func (f *fmt) pad(b []byte) {
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags()
+ if !f.preserveFlags {
+ f.clearflags()
+ }
}
// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus).
@@ -137,7 +140,9 @@ func (f *fmt) padString(s string) {
if right > 0 {
f.writePadding(right, padding)
}
- f.clearflags()
+ if !f.preserveFlags {
+ f.clearflags()
+ }
}
func putint(buf []byte, base, val uint64, digits string) int {
@@ -425,6 +430,7 @@ func (f *fmt) fmt_fb32(v float32) { f.padString(strconv.Ftoa32(v, 'b', 0)) }
func (f *fmt) fmt_c64(v complex64, fmt_x byte) {
f.buf.WriteByte('(')
r := real(v)
+ f.preserveFlags = true
for i := 0; ; i++ {
switch fmt_x {
case 'e':
@@ -438,6 +444,7 @@ func (f *fmt) fmt_c64(v complex64, fmt_x byte) {
case 'G':
f.fmt_G32(r)
}
+ f.preserveFlags = false
if i != 0 {
break
}
@@ -452,6 +459,7 @@ func (f *fmt) fmt_c64(v complex64, fmt_x byte) {
func (f *fmt) fmt_c128(v complex128, fmt_x byte) {
f.buf.WriteByte('(')
r := real(v)
+ f.preserveFlags = true
for i := 0; ; i++ {
switch fmt_x {
case 'e':
@@ -465,6 +473,7 @@ func (f *fmt) fmt_c128(v complex128, fmt_x byte) {
case 'G':
f.fmt_G64(r)
}
+ f.preserveFlags = false
if i != 0 {
break
}