Commit e97789f7 authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Rob Pike

fmt: simplify handling of reporting flags to formatters

Remove rewriting of flags before calling formatters.
Change Flag method to directly take plusV and sharpV flags
into account when reporting if plus or sharp flag is set.

Change-Id: Ic3423881ad89e5a5f9fff5ab59e842062394ef6d
Reviewed-on: https://go-review.googlesource.com/20859
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 15ea6114
......@@ -152,9 +152,9 @@ func (p *pp) Flag(b int) bool {
case '-':
return p.fmt.minus
case '+':
return p.fmt.plus
return p.fmt.plus || p.fmt.plusV
case '#':
return p.fmt.sharp
return p.fmt.sharp || p.fmt.sharpV
case ' ':
return p.fmt.space
case '0':
......@@ -570,34 +570,6 @@ func (p *pp) catchPanic(arg interface{}, verb rune) {
}
}
// clearSpecialFlags pushes %#v back into the regular flags and returns their old state.
func (p *pp) clearSpecialFlags() (plusV, sharpV bool) {
plusV = p.fmt.plusV
if plusV {
p.fmt.plus = true
p.fmt.plusV = false
}
sharpV = p.fmt.sharpV
if sharpV {
p.fmt.sharp = true
p.fmt.sharpV = false
}
return
}
// restoreSpecialFlags, whose argument should be a call to clearSpecialFlags,
// restores the setting of the plusV and sharpV flags.
func (p *pp) restoreSpecialFlags(plusV, sharpV bool) {
if plusV {
p.fmt.plus = false
p.fmt.plusV = true
}
if sharpV {
p.fmt.sharp = false
p.fmt.sharpV = true
}
}
func (p *pp) handleMethods(verb rune, depth int) (handled bool) {
if p.erroring {
return
......@@ -605,7 +577,6 @@ func (p *pp) handleMethods(verb rune, depth int) (handled bool) {
// Is it a Formatter?
if formatter, ok := p.arg.(Formatter); ok {
handled = true
defer p.restoreSpecialFlags(p.clearSpecialFlags())
defer p.catchPanic(p.arg, verb)
formatter.Format(p, verb)
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment