summaryrefslogtreecommitdiff
path: root/libgo/go/fmt/print.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/fmt/print.go')
-rw-r--r--libgo/go/fmt/print.go41
1 files changed, 32 insertions, 9 deletions
diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go
index f29e8c8e9f1..13e58737f96 100644
--- a/libgo/go/fmt/print.go
+++ b/libgo/go/fmt/print.go
@@ -569,24 +569,27 @@ func (p *pp) fmtBytes(v []byte, verb rune, goSyntax bool, depth int) {
}
return
}
- s := string(v)
switch verb {
case 's':
- p.fmt.fmt_s(s)
+ p.fmt.fmt_s(string(v))
case 'x':
- p.fmt.fmt_sx(s, ldigits)
+ p.fmt.fmt_bx(v, ldigits)
case 'X':
- p.fmt.fmt_sx(s, udigits)
+ p.fmt.fmt_bx(v, udigits)
case 'q':
- p.fmt.fmt_q(s)
+ p.fmt.fmt_q(string(v))
default:
p.badVerb(verb)
}
}
func (p *pp) fmtPointer(value reflect.Value, verb rune, goSyntax bool) {
+ use0x64 := true
switch verb {
- case 'p', 'v', 'b', 'd', 'o', 'x', 'X':
+ case 'p', 'v':
+ // ok
+ case 'b', 'd', 'o', 'x', 'X':
+ use0x64 = false
// ok
default:
p.badVerb(verb)
@@ -616,7 +619,11 @@ func (p *pp) fmtPointer(value reflect.Value, verb rune, goSyntax bool) {
} else if verb == 'v' && u == 0 {
p.buf.Write(nilAngleBytes)
} else {
- p.fmt0x64(uint64(u), !p.fmt.sharp)
+ if use0x64 {
+ p.fmt0x64(uint64(u), !p.fmt.sharp)
+ } else {
+ p.fmtUint64(uint64(u), verb, false)
+ }
}
}
@@ -735,8 +742,17 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth
return false
}
- if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
- return wasString
+ // Clear flags for base formatters.
+ // handleMethods needs them, so we must restore them later.
+ // We could call handleMethods here and avoid this work, but
+ // handleMethods is expensive enough to be worth delaying.
+ oldPlus := p.fmt.plus
+ oldSharp := p.fmt.sharp
+ if plus {
+ p.fmt.plus = false
+ }
+ if goSyntax {
+ p.fmt.sharp = false
}
// Some types can be done without reflection.
@@ -780,6 +796,13 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth
p.fmtBytes(f, verb, goSyntax, depth)
wasString = verb == 's'
default:
+ // Restore flags in case handleMethods finds a Formatter.
+ p.fmt.plus = oldPlus
+ p.fmt.sharp = oldSharp
+ // If the type is not simple, it might have methods.
+ if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
+ return wasString
+ }
// Need to use reflection
return p.printReflectValue(reflect.ValueOf(field), verb, plus, goSyntax, depth)
}